The documentation for Array#shuffle
states:
shuffle(random: rng) → new_ary
The optional
rng
argument will be used as the random number generator.a.shuffle(random: Random.new(1)) #=> [1, 3, 2]
If I don't supply the optional random
argument, what is used for it?
Equivalently, if I call a.shuffle(random: rng)
, what does rng
need to be to make it the same as just a.shuffle
?
CodePudding user response:
It's right in the signature, shuffle(random: Random)
. That says the default value for random
is the Random
Class object.
The class method
Random.rand
provides the base functionality ofKernel.rand
along with better handling of floating point values. These are both interfaces to the Ruby system PRNG.