Open In App

Ruby | Random rand() function

Improve
Improve
Like Article
Like
Save
Share
Report

Random#rand() : rand() is a Random class method which generates a random value.

Syntax: Random.rand()

Parameter: Random values

Return: generates a random value.

Example #1 :




# Ruby code for Random.rand() method
  
# declaring Random value
date_a = Random.rand()
  
# new arbitrary random value
puts "Random form : #{date_a}\n\n"


Output :

Random form : 0.19492446216402715

Example #2 :




# Ruby code for Random.rand() method
  
# declaring Random value
date_b = Random.rand()
  
date_a = Random.rand(10)
  
# new arbitrary random value
puts "Random form : #{date_b}\n\n"
  
puts "Random form : #{date_a}\n\n"


Output :

Random form : 0.175729980681539

Random form : 1


Last Updated : 17 Dec, 2019
Like Article
Save Article
Previous
Next
Share your thoughts in the comments
Similar Reads