0

Is it guaranteed by the standard that if std::mt19937 was seeded by the same number, it will produce the same sequence of numbers on all platforms?

In other words, is its implementation well-defined by the standard or it is like std::rand() which was considered as implementation details?

Humam Helfawi
  • 19,566
  • 15
  • 85
  • 160

1 Answers1

6

In [rand.eng.mars] 1-5 the passage basically sums up the implementation details for the mersenne twister algorithm.

std::mt19937 is just a typedef for

using mt19937 =
      mersenne_twister_engine<uint_fast32_t,
       32,624,397,31,0x9908b0df,11,0xffffffff,7,0x9d2c5680,15,0xefc60000,18,1812433253>;

And all the standard says about the expected results is that :

Required behavior: The 10000 th consecutive invocation of a default-constructed object of type mt19937 shall produce the value 4123659995.

No other guarantees are made.

However, because the std::mersenne_twister_engine is required to follow the mersenne twister PRNG implementation it's implementation is well defined.

Hatted Rooster
  • 35,759
  • 6
  • 62
  • 122
  • for someone unfamiliar with the random generator algorithms (like me) this sounds like a very very strange requirement. – bolov Sep 28 '16 at 08:22
  • 1
    @bolov read 1-5 in rand.eng.mars, that's basically a summary of the implementation of the mersenne twister PRNG. – Hatted Rooster Sep 28 '16 at 08:23
  • @bolov This requirement is not really useful since the behavior of `std::mersenne_twister_engine` and its default seed are already well-defined by the standard. – Holt Sep 28 '16 at 08:37
  • @bolov - it does sound strange, but it's a very handy check when you're implementing the algorithm. – Pete Becker Sep 28 '16 at 12:58