5 ms·
"There are some tricks to improve the randomness of the computer generated numbers... For instance, you could have the program sleep for a randomly generated am
by Hexstream 18y ago
"There are some tricks to improve the randomness of the computer generated numbers... For instance, you could have the program sleep for a randomly generated amount of milliseconds before grabbing the next random number... or add, subtract, divide, and multiply the random numbers with other random numbers."
I'm no PRNG expert but I think I read somewhere that those techniques wouldn't significantly improve the quality of pseudo-randomness, if at all. You can't mix 2 bad wines to get a good one.
- scott_s 18y agoI had glanced over that paragraph, and indeed, it's wrong. One, the stream only changes if the seed is dependent on the system time. Two, if you modify the result with another pseudo-random number, then you have a function whose randomness if as only as good as its inputs.
- stcredzero 18y agoIf you just want a PRNG for a game, then sending the output of a bad PRNG through a hash function like MD5 will almost always give you good results. That would've been better advice. Also, the mouse is a readily available source of randomness which can also suffice for a game. As far as PRNGs for cryptographic purposes, that's something else entirely. (By conincidence, I am going to be writing a game which uses cryptographically secure algorithms to generate random numbers for a procedurally generated game world. (A Galaxy of 400 Billion Stars!)
- stcredzero 18y agoIf the PRNG is really bad, then even this won't work. But PRNGs that bad are generally deliberately made that bad.