@@ -69,15 +69,24 @@ def shuffle!(random: Random)
6969 end
7070
7171 # call-seq:
72- # array. shuffle(random: Random) -> new_ary
72+ # shuffle(random: Random) -> new_array
7373 #
74- # Returns a new array with elements of +self+ shuffled.
75- # a = [1, 2, 3] #=> [1, 2, 3]
76- # a.shuffle #=> [2, 3, 1]
77- # a #=> [1, 2, 3]
74+ # Returns a new array containing all elements from +self+ in a random order,
75+ # as selected by the object given by keyword argument +random+:
7876 #
79- # The optional +random+ argument will be used as the random number generator:
80- # a.shuffle(random: Random.new(1)) #=> [1, 3, 2]
77+ # a = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
78+ # a.shuffle # => [0, 8, 1, 9, 6, 3, 4, 7, 2, 5]
79+ # a.shuffle # => [8, 9, 0, 5, 1, 2, 6, 4, 7, 3]
80+ #
81+ # Duplicate elements are included:
82+ #
83+ # a = [0, 1, 0, 1, 0, 1, 0, 1, 0, 1]
84+ # a.shuffle # => [1, 0, 1, 1, 0, 0, 1, 0, 0, 1]
85+ # a.shuffle # => [1, 1, 0, 0, 0, 1, 1, 0, 0, 1]
86+ #
87+ # The object given with keyword argument +random+ is used as the random number generator.
88+ #
89+ # Related: see {Methods for Fetching}[rdoc-ref:Array@Methods+for+Fetching].
8190 def shuffle ( random : Random )
8291 Primitive . rb_ary_shuffle ( random )
8392 end
0 commit comments