I'm generating a sequence of random numbers with std::mt19937_64. I've noticed that, when run with GCC and Clang on the same platform with the same seed, I obtain a different sequence. I've run the program through Valgrind and found no uninitialized memory.
Is there any guarantee to reproducibility across compilers or across platforms with std::mt19937_64?
Edit: Running with std::normal_distribution
The Mersenne Twister is widely regarded as good. Heck, the CPython source says that it "is one of the most extensively tested generators in existence." But what does this mean? When asked to list properties of this generator, most of what I can offer is bad: It's massive and inflexible (eg.
Implementations generally create random numbers faster than hardware-implemented methods. A study found that the Mersenne Twister creates 64-bit floating point random numbers approximately twenty times faster than the hardware-implemented, processor-based RDRAND instruction set.
you start with a seed (if you re-use the same seed you will obtain the same random numbers), you initialize it into a state . Then, every time you want to obtain a random number, you transform that state with a one-way function g . This is because you don't want people to find out the state out of the random output.
The Mersenne Twister is a strong pseudo-random number generator. In non-rigorous terms, a strong PRNG has a long period (how many values it generates before repeating itself) and a statistically uniform distribution of values (bits 0 and 1 are equally likely to appear regardless of previous values).
The numbers that engines generate are guaranteed to be reproducible across implementations, but the distributions are not. (source: rand() considered harmful).
The N3337 standard draft says this about normal_distribution
(26.5.8.5.1):
A normal_distribution random number distribution produces random numbers x distributed according to the probability density function
The distribution parameters µ and σ are also known as this distribution’s mean and standard deviation
And... that's it. It doesn't specify the order of the generated numbers, nor algorithm, nor example outputs.
The standard is very elaborate about mersenne_twister_engine
(26.5.3.2), it specifies the state transition function, initial seeding algorithm and so on.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With