Generating Random Numbers in Ruby
Ruby provided Kernel.rand function without arguments in order to generate random number between 0 and 1. If you pass a single integer to this method then the random number will be generated between 0 and n-1.
In addition, Ruby allows you to use random function to pick a member of an array at random such as:
a = ['item 1', 'item 2', 'item 3']
a[rand(a.size)]
Randomization can be applied hashes pretty much the same way you would apply to array in Ruby.
m = { key1: 'value 1', key2: 'value 2', key3: 'value 3' }
values = m.values
values[rand(values.size)]