Random number generation

suggest change

arc4random_uniform(someNumber: UInt32) -> UInt32

This gives you random integers in the range 0 to someNumber - 1.

The maximum value for UInt32 is 4,294,967,295 (that is, 2^32 - 1).

Examples:

let flip = arc4random_uniform(2) // 0 or 1
let roll = arc4random_uniform(6) + 1 // 1...6
let day = arc4random_uniform(31) + 1 // 1...31
let year = 1990 + arc4random_uniform(10)

General form:

let number = min + arc4random_uniform(max - min + 1)

where number, max, and min are UInt32.

Notes

Feedback about page:

Feedback:
Optional: your email if you want me to get back to you:



Table Of Contents