Ruby Newbie homepage Ruby Newbie homepage

How to use

Quick guide

Official content
Returns a new array with elements of self shuffled.
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:
a.shuffle(random: Random.new(1))  #=> [1, 3, 2]
 
               # File array.rb, line 26
def shuffle(random: Random)
  Primitive.rb_ary_shuffle(random)
end
            

Was this page useful?