Cocoa-Matic

iPhone, iPod touch, iPad tutorials, examples and sample code. Come and get it!

Tuesday, August 17, 2010

Random Number in Cocoa and Objective-c

Generating a random number is fairly simple using arc4random(). Say you want a random integer between 10 (min) and 1000 (max). Here's how to do it:

int max = 1000;
int min = 10;
int value = (arc4random() % max) + min;

Also, no need to do any seeding with this method.

Labels: ,

1 Comments:

Post a Comment

Subscribe to Post Comments [Atom]



<< Home


« Older Entries  
Newer Entries »