This
std::mt19937 gen(123);
std::normal_distribution<> distr(0., .2);
printf("%f", distr(gen));
prints 0.339167
on my OSX 10.9 machine (built with clang 3.5) but prints -0.113922
on a linux box (gcc 4.8). I was expecting to see the same results everywhere.
When inspecting the underlying stream from mt19937, I see a consistent sequence of numbers on both platforms. So it appears that the platform inconsistency is in std::normal_distribution.
Is this expected behavior? Is there a way that I can set this up so that I am guaranteed to get the same results everywhere?
std::mt19937
and siblings are very specific algorithms. The standard requires that e.g. The 10000th consecutive invocation of a default-constructed object of type mt19937 shall produce the value 4123659995. There's no wiggle room here.
std::normal_distribution
and siblings, by contrast, are only required to produce results distributed according to a certain probability density function. There is no requirement for them to be any specific function.
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