Reputation: 175
Code example:
#include <iostream>
#include <random>
using namespace std;
int main()
{
mt19937 generator(0);
uniform_int_distribution<int> distr(0, 100);
for(auto i = 0; i < 10; ++i)
{
cout << distr(generator) << "\n";
}
}
This code produces different numbers on Mac and Windows, but replacing uniform_int_distribution
with uniform_real_distribution
fixes that issue, and sequence generated is the same on both platforms.
Why does this happen?
Upvotes: 1
Views: 442
Reputation: 477070
The algorithm for distributions is not specified, different implementations may produce different results.
(The only thing the standard does specify are the raw random bit engines; those produce predictable results.)
Upvotes: 5