You can use the rand
method in Ruby to generate a uniformly distributed random number. By default, it generates a random float between 0.0 and 1.0.
main.rb226 chars12 lines
If you need to generate a random number within a specific range, you can use the rand
method with a range object as an argument. The range object can be created using the ..
operator, and you can specify the lower and upper bounds of the range.
By providing an integer as an argument to the rand
method, you can generate a random integer within the specified range, from 0 up to, but not including, the provided integer.
Keep note that if you want to set the seed for the random number generator, you'll want to call srand
with a seed value before calling rand
.
gistlibby LogSnag