Actions
Bug #19100
closedRuby 3 PRNG values diverge from Ruby 2 for some initial values
Description
The outputs of the Mersenne Twister implementation diverged from their expected results in Ruby 2 for initial pseudo-random number generator seeds between 2^32 and 2^33-1, inclusive. I used ruby versions 2.7.4 vs. 3.0.3, 3.0.4, and 3.1.2 to compare.
ARBITRARY_RAND_MAX = 2**32
# The below three outputs should generate different outputs in ruby 2 and ruby 3
prng = Random.new(2**32)
puts prng.seed
puts prng.rand(ARBITRARY_RAND_MAX)
prng2 = Random.new(2**33-1)
puts prng2.seed
puts prng2.rand(ARBITRARY_RAND_MAX)
prng3 = Random.new((2**32 + 2**33-1) / 2)
puts prng3.seed
puts prng3.rand(ARBITRARY_RAND_MAX)
# These next two examples should generate the same outputs in ruby 2 and ruby 3
prng4 = Random.new(2**32 - 1)
puts prng4.seed
puts prng4.rand(ARBITRARY_RAND_MAX)
prng5 = Random.new(2**33)
puts prng5.seed
puts prng5.rand(ARBITRARY_RAND_MAX)
Actions
Like0
Like0Like0Like0