How To Generate Random Number In Ruby

3 September 2009

To generate a random number in ruby, use rand(n). rand(n) will give you a random number from 0 to n-1.

rand(9) # will give you a random number from 0-8 inclusive.