method
shuffle
v2_1_10 -
Show latest stable
- Class:
Array
shuffle(*args)public
Returns a new array with elements of self shuffled.
a = [ 1, 2, 3 ] #=> [1, 2, 3] a.shuffle #=> [2, 3, 1]
The optional rng argument 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