Instance method
# shuffle
Returns a new array with elements of self shuffled.
How to use
Quick guide
Official content
Official how?
I scraped all this data from the official documentation. I created this site to make it easier for beginners and more pleasant for professionals to use Ruby.
Georgie boy
Creator of ruby-docs.org
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?
Leave your feedback
Please hit 'submit' to confirm your feedback.
Leave your feedback
Please hit 'submit' to confirm your feedback.