Can identical sequences be calculated based on srand?


A purely philosophical question:

Can you rely on the randomization base to generate identical sequences on different devices?

For example, setting some base (srand) and generating 100 numbers, can you be sure that these very numbers will be generated with the same base on a faster / slower computer / phone etc ..?

PS At the heart of the question is the srand function from the C standard library.
PPS Different compilers produce different sequences.


No. The implementation of srand depends on the C standard library being used – and it may differ on different computers. And even on the same computer, it may differ. Even if compiled with the same compiler.

If you need a portable deterministic pseudo-random number generator, it's better to write it yourself.

Scroll to Top