I'm making a game in C++ and it involves filling tiles with random booleans (either yes or no) whether it is yes or no is decided by rand() % 1
. It doesn't feel very random.
I'm using srand
with ctime
at startup, but it seems like the same patterns are coming up.
Are there any algorithms that will create very random numbers? Or any suggestions on how I could improve rand()
?
Knuth suggests a Random number generation by subtractive method. Its is believed to be quite randome. For a sample implementation in the Scheme language see here
Also if you reseed too fast then you will get the exact same number. Personally I use a class that updates the seed only when the time has changed.