How I can generate list of random values in Ruby from a list of numbers?
[100, 643, 826, 804, 372, 076, 156, 152, 036, 248]
How I can pick one random number from the list?
How I can generate list of random values in Ruby from a list of numbers?
[100, 643, 826, 804, 372, 076, 156, 152, 036, 248]
How I can pick one random number from the list?
Just use Array#sample
:
[100, 643, 826, 804, 372, 076, 156, 152, 036, 248].sample
Available in Ruby 1.9.1+. In an earlier version of Ruby, you could
require 'backports/1.9.1/array/sample'