Random numbers on different systems

Hi guys,

I have a question:

If I use

1
2
3
4
5
std::seed_seq seq{1,20,3200,403,5*randomseed+1,12000,73667,9474+randomseed,19151-randomseed};
std::vector<std::uints32_t> seeds(3);
seq.generate(seeds.begin(), seeds.end());
std::mt19937 genx(seeds.at(0));
std::uniform_real_distribution<> disx(a,b);


with "randomseed", "a", and "b" some input parameters,

and if I sample random numbers via disx(genx), will I get the same random numbers on different computers/systems?

What happens, if "a" and "b" are the result of floating point calculations? I would expect to obtain different rounding errors and thus different random-number results?

Best,
PiF
Last edited on
no, it won't. Same compiler has a good chance of being the same but you can't bet on it.

rounding should be about the same, floating point is done in the FPU not the language, but the FPUs could be different (esp if one machine is older than another or special purpose).
So if I get an error at a certain random seed, it is no use to try to reproduce the error on a different machine using the same random seed, since the obtained random numbers are different.

Thank you!
More specifically, the Mersenne Twister generator is fully specified, and should produce the same outputs given the same seed on any system (e.g. calling genx() directly). But the distributions (e.g. uniform_int_distribution) can be different on different platforms.

Also, mt19937 can take in a seed_seq in its constructor.
Last edited on
Good point, I had forgotten that.
The handling of the floating point is still going to give tiny variations if the hardware is significantly different, eg internally 80 bits, 96 bits, 128 bits, etc several formats exist. 80 is the most common PC format I think, or it was... I am out of the loop a bit.
Thank you guys!
Topic archived. No new replies allowed.