Join GitHub today
GitHub is home to over 40 million developers working together to host and review code, manage projects, and build software together.Sign up
Implement support for random seeds for fully reproducible results #3
A classical random number generators used across threads leads to massive performance degradation due to concurrent access. To alleviate this, Java uses ThreadLocalRandom as a substitute which is thread-safe and efficient. The problem now is that ThreadLocalRandom does not support setting seeds. In general, it is difficult to ensure that results are fully reproducible in parallel execution. Even if every thread uses its own number generators, we can not guarantee the exact order of triplets tested since this depends on the somewhat random execution speed of each thread...
In summary, we can use random seeds but this will make things considerably slower...
After playing with the BetterRandom library for a while I now simply implemented the following:
if the user sets a seed, for each triplet a local Random number generator will be started with that seed, making the results reproducible.
If a seed is not set, ThreadLocalRandom() is used to coordinate random seeding across all threads, leading to a more random shuffling.