1

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?

templatetypedef
  • 362,284
  • 104
  • 897
  • 1,065
sandyre
  • 175
  • 2
  • 9

1 Answers1

5

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.)

Kerrek SB
  • 464,522
  • 92
  • 875
  • 1,084