Skip to content
Related Articles

Related Articles

Improve Article
Save Article
Like Article

Ruby | Random rand() function

  • Last Updated : 17 Dec, 2019

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

My Personal Notes arrow_drop_up
Recommended Articles
Page :

Start Your Coding Journey Now!