method
shuffle
v1_9_3_392 -
Show latest stable
- Class:
Array
shuffle(*args)public
Returns a new array with elements of this array shuffled.
a = [ 1, 2, 3 ] #=> [1, 2, 3] a.shuffle #=> [2, 3, 1]
If rng is given, it will be used as the random number generator.
a.shuffle(random: Random.new(1)) #=> [1, 3, 2]
1Note
See also: sample
sample randomly picks 1 or n elements from the array