Srand (time (null)) on iPhone does not work = (

I need to generate random numbers in my iPhone game. I am using the rand () function. But this is not enough. I tried using srand with time (Null). But my random generator was periodic. / dev / random is not the answer, because I need a new random number every 0.1 sec.

0
source share
3 answers

On iOS and OS X, use arc4random . Higher quality of randomness and no need to worry about sowing.

However, rand()it should not be periodic if you do not call srandevery time. Or use random numbers incorrectly.

+4
source

random()/srandom(). , rand()/srand().

+3

Are you building for debugging or on a simulator? I know that I encountered such a problem when creating some windowed applications during debugging, the RNG was automatically seeded with a constant value to get consistent results. You may want to check what it actually sows, and if you get different outputs every time you start.

0
source

All Articles