C ++ normal_distribution gives different results on different platforms

it

std::mt19937 gen(123); std::normal_distribution<> distr(0., .2); printf("%f", distr(gen)); 

prints 0.339167 on my OSX 10.9 computer (built with clang 3.5), but prints -0.113922 in the linux window (gcc 4.8). I expected to see the same results everywhere.

When checking the base stream from mt19937, I see a sequential sequence of numbers on both platforms. So it seems that platform inconsistency is in std :: normal_distribution.

Is this the expected behavior? Is there a way I can set this to ensure that I get the same results everywhere?

+6
source share
1 answer

std::mt19937 , and siblings are very specific algorithms. The standard requires, for example, a Successive call of 10000th of a successive call to an object constructed by default of type mt19937, should have the value 4123659995. There is no room for maneuver.

std::normal_distribution , and brothers and sisters, by contrast, are only needed to obtain results distributed over a certain probability density function. For them, there is no need for any particular function.

+6
source

Source: https://habr.com/ru/post/977508/


All Articles