To generate a random number in Ruby, you can use the rand
method.
main.rb138 chars6 lines
The rand
method can also accept an argument to specify a range of numbers. For example:
main.rb161 chars6 lines
Keep in mind that rand
generates a pseudorandom number, which means that the sequence of numbers may not be truly random, but they'll appear random enough for most practical purposes.
gistlibby LogSnag