In other words, if I create a QRandomGenerator
with seed N in Qt version X, is it guaranteed to produce the same sequence as a QRandomGenerator
created with the same seed N in Qt version Y?
The documentation only seems to imply determinism within a given version of Qt.
CodePudding user response:
Generally, excepted if you write yourself a Mersenne Twister (or other similar PSEUDO-random generator) and know for sure that its output will be consistent across platforms (think about endianness, 32/64 bits, compiler optimizations, CPU speed, ...), you should NEVER EVER rely on a pseudo-random generator to deliver the same sequence on each run, whatever seed you used. QRandomGenerator
isn't an exception.
Even without recompiling the binary, it may change if you change the execution platform (i.e. running it on another machine).
It's also why it isn't reliable to use a pseudo-random generator as a cryptographic system in itself.
CodePudding user response:
Everything you need to know is right there, in the docs:
QRandomGenerator may be used to generate random values from a high-quality random number generator. Like the C random engines, QRandomGenerator can be seeded with user-provided values through the constructor. When seeded, the sequence of numbers generated by this class is deterministic. That is to say, given the same seed data, QRandomGenerator will generate the same sequence of numbers. But given different seeds, the results should be considerably different.
And you can't say anything about different versions because they don't have to be compatible but I'd expect that within a major version you can count on it. Also you can check the implementation of each version you need to make sure it is the same.