Search code examples
c++randomdeterministicnon-deterministic

Sources of non-determinism


My supposedly deterministic program produces one of a few slightly different outputs on different runs. The input, compiler and computer are unchanging. I'm not sure which output is right because it always looks reasonable.

Besides a stray call to rand(), how could this be possible?


Solution

  • In several ways:

    • using multiple threads in a way that involves a data race,
    • using the current system time as input,
    • using uninitialized variables,
    • ...

    We can surely make more guesses, but if you want to get meaningful help, maybe it would be good for you to publish the relevant parts of your code :-)