@PSWorx said:
// Allow this to be instantiated in parallel in multiple threadsOn the risk of introducing even more stupidity, this brings up something I've wondered for some time already: Couldn't you create a pretty good "true" random number generator using a kind of "controlled race condition"?
Imagine something like this:
// Thread 1:
forever {
number++; // adjust actual formulas for uniform distribution
sleep(1);
}// Thread 2:
forever {
number--;
sleep(1);
}// Thread 3:
int getRandomNumber() {
return number;
}Of course this is still technically deterministic, but would actually depend on so many different variables - many of them changing over time even - that it didn't matter. Or would it?
Where is the flaw?
Well, this would almost always return the same number.
Better would be taking a cryptographically secure hash of a pseudo random number and the system time.