Archive for May, 2009

Random int in Cocoa on the iPhone

Friday, May 1st, 2009

So you just need a random int value in Objective-C? Here you go. The following code produces a random int between 0 and 4:

srandom(time(NULL));
int i = random()%4;

Please note, this is NOT a very efficient way to get randoms. Use it only to get a relativly random number every now and then ;)