Maintenance Ruby 3.3 gets fixes, but no new features. Switch to Ruby 4.0 →
instance method
Array#shuffle!
array.shuffle!(random: Random) → array
array.rb
View on GitHub ↗
# File tmp/rubies/ruby-3.3.0/array.rb, line 12
def shuffle!(random: Random)
Primitive.rb_ary_shuffle_bang(random)
end
Shuffles the elements of self in place.
Example
a = [1, 2, 3] #=> [1, 2, 3] a.shuffle! #=> [2, 3, 1] a #=> [2, 3, 1]
The optional random argument will be used as the random number generator:
Example
a.shuffle!(random: Random.new(1)) #=> [1, 3, 2]