I tested the random number generator seeded with the same number, I am supposed to get the same result each time I run the program. And that's the case on the same computer. However, when I compile it on a different computer, I can get the same sequence repeatedly every time I run, but the results are different across computers. Is it caused by different implementation from the compiler of different version? I wonder if there is any library that is not dependent on the compiler or kernel or hardwares? I have tested rand(), mt19937, and default_random_engine. They all behaved the same.
srand (1);
cout<<rand()<<endl;
cout<<rand()<<endl;
cout<<rand()<<endl;
cout<<rand()<<endl;
cout<<rand()<<endl;
std::default_random_engine generator(1);
std::uniform_int_distribution<int> distribution(0,100000);
cout<<distribution(generator)<<endl;
cout<<distribution(generator)<<endl;
cout<<distribution(generator)<<endl;
cout<<distribution(generator)<<endl;
cout<<distribution(generator)<<endl;
std::random_device dev;
std::mt19937 rng(1);
std::uniform_int_distribution<std::mt19937::result_type> dist6(1,10000);
cout<<dist6(rng)<<endl;
cout<<dist6(rng)<<endl;
cout<<dist6(rng)<<endl;
cout<<dist6(rng)<<endl;
cout<<dist6(rng)<<endl;
exit(0);
The outputs are:
16807
282475249
1622650073
984943658
1144108930
48270
22497
73541
20860
47696
236
5193
906
7814
2896
Program ended with exit code: 0