Random with a range : rand « Development « Ruby






Random with a range


puts rand(5)            # => 0
puts rand(5)            # => 4
puts rand(5)            # => 3
puts rand(1000)         # => 39

 








Related examples in the same category

1.Generating Random Numbers
2.Get a random item in an array
3.Get a random value in a hash
4.Generate random numbers
5.Some random numbers based on process number and current time
6.Start the seed with the number 1