How to randomly sort (scramble) an array in Ruby?
For ruby 1.8.6 (which does not have shuffle built in):
array.sort_by { rand }
Built in now:
[1,2,3,4].shuffle => [2, 1, 3, 4]
[1,2,3,4].shuffle => [1, 3, 2, 4]
For ruby 1.8.6 (which does not have shuffle built in):
array.sort_by { rand }
Built in now:
[1,2,3,4].shuffle => [2, 1, 3, 4]
[1,2,3,4].shuffle => [1, 3, 2, 4]