End of Life Ruby 3.0 has reached end of life and gets no more fixes. Switch to Ruby 4.0 →
instance method
Array#shuffle
array.shuffle(random: Random) → new_ary
array.rb
View on GitHub ↗
# File tmp/rubies/ruby-3.0.5/array.rb, line 26
def shuffle(random: Random)
Primitive.rb_ary_shuffle(random)
end
Returns a new array with elements of self shuffled.
Example
a = [1, 2, 3] #=> [1, 2, 3] a.shuffle #=> [2, 3, 1] a #=> [1, 2, 3]
The optional random argument will be used as the random number generator:
Example
a.shuffle(random: Random.new(1)) #=> [1, 3, 2]