Objective-C Language Random Integer Basic Random Integer

Help us to keep this website almost Ad Free! It takes only 10 seconds of your time:
> Step 1: Go view our video on YouTube: EF Core Bulk Insert
> Step 2: And Like the video. BONUS: You can also share it!

Example

The arc4random_uniform() function is the simplest way to get high-quality random integers. As per the manual:

arc4random_uniform(upper_bound) will return a uniformly distributed random number less than upper_bound.

arc4random_uniform() is recommended over constructions like ''arc4random() % upper_bound'' as it avoids "modulo bias" when the upper bound is not a power of two.

uint32_t randomInteger = arc4random_uniform(5); // A random integer between 0 and 4


Got any Objective-C Language Question?