Objective-C Language Random Integer within a Range


Example

The following code demonstrates usage of arc4random_uniform() to generate a random integer between 3 and 12:

uint32_t randomIntegerWithinRange = arc4random_uniform(10) + 3; // A random integer between 3 and 12

This works to create a range because arc4random_uniform(10) returns an integer between 0 and 9. Adding 3 to this random integer produces a range between 0 + 3 and 9 + 3.