Search code examples
xcodeios4xcode4xcode4.2

rand() doesn't seem to be so random


Here is how i'm creating the int:

int randNumber = rand() % 4;
NSLog(@"%d", randNumber);

However every time I launch the app the number is the same, no matter what.

I created a button and attached an action to it that re-initializes the random number and logs the new number out and then it generates a random number, but on App launch the random number is always the same (i've launched it over 20 times).

Any idea why on app launch the random number is always the same?


Solution

  • Try using arc4random(), which doesn't require a seed