The arc4random() function returns pseudo-random numbers in the range of 0 to (2*32)-1
The arc4random()
function uses the key stream generator employed by the arc4 cipher, which uses 8*8 8 bit S-Boxes. The S-Boxes can be in about (2*1700) states. The arc4random()
function returns pseudo-random numbers in the range of 0 to (2*32)-1, and therefore has twice the range of rand()
and random()
.
For example, a drop-in replacement for the traditional rand() and random() functions using arc4random():
#define foo4random() (arc4random() % ((unsigned)RAND_MAX + 1))