红宝石 |随机 rand()函数
Random#rand() : rand()是一个 Random 类方法,它生成一个随机值。
Syntax: Random.rand()
Parameter: Random values
Return: generates a random value.
示例 #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"
输出 :
Random form : 0.19492446216402715
示例 #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"
输出 :
Random form : 0.175729980681539
Random form : 1