Saturday, May 23, 2009

random() on the iphone SDK giving same values

I obviously had changed the random seed with srand(time(NULL)) however when generating 4 random numbers they were always the same although always different with each run. I thought I was going insane as when I tried debugging it step by step the numbers generated were different.

After googling a bit I found that it is better to use arc4random(). That fixed it.

No comments: