random

random integers

rand(1..5)
#=> one of 1, 2, 3, 4, 5

rand(1...5)
#=> one of 1, 2, 3, 4

rand(5)
#=> one of 0, 1, 2, 3, 4
#random floats

rand(5.0)
#=> one of integers 0, 1, 2, 3, 4, no floats

rand(0.0..5.0)
#=> one of floats 0.0 ~ 5.0

rand(1.0..5.0)
#=> one of floats 1.0 ~ 5.0

Reference

results matching ""

    No results matching ""