Sample code for 30+ languages & platforms
Objective-C

Generating Random Integer in Range

See more PRNG Examples

Demonstrates how to generate random integers in a specified range.

Chilkat Objective-C Downloads

Objective-C
#import <CkoPrng.h>

BOOL success = NO;

// This example assumes the Chilkat API to have been previously unlocked.
// See Global Unlock Sample for sample code.

success = NO;

CkoPrng *fortuna = [[CkoPrng alloc] init];

// Generate random integers between 12 and 24 inclusive
int i;
for (i = 0; i <= 100; i++) {
    NSLog(@"%d",[[fortuna RandomInt: [NSNumber numberWithInt: 12] high: [NSNumber numberWithInt: 24]] intValue]);
}