From: "nobu (Nobuyoshi Nakada)" Date: 2022-11-09T10:49:00+00:00 Subject: [ruby-core:110668] [Ruby master Bug#19100] Ruby 3 PRNG values diverge from Ruby 2 for some initial values Issue #19100 has been updated by nobu (Nobuyoshi Nakada). This is a mistake on the interface. The cause is MT initialization by single word is not distinguished from initialization by array now. In other words, leading-zero-guard is just stripped but ignored. Another initializer function is needed to fix this issue, but just adding it will break the binary compatibility. This [patch] adds versioning to `rb_random_interface_t` and function member for initialization by single word. [patch]: https://github.com/ruby/ruby/pull/6697 ---------------------------------------- Bug #19100: Ruby 3 PRNG values diverge from Ruby 2 for some initial values https://bugs.ruby-lang.org/issues/19100#change-100012 * Author: mweitekamp (Monica Weitekamp) * Status: Assigned * Priority: Normal * Assignee: nobu (Nobuyoshi Nakada) * ruby -v: 3.1.2 * Backport: 2.7: UNKNOWN, 3.0: UNKNOWN, 3.1: UNKNOWN ---------------------------------------- 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. ``` ruby 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) ``` -- https://bugs.ruby-lang.org/ Unsubscribe: