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 pseudorandom
random numbers in the range of 0 to (2**32)-1, and therefore has twice the range of rand(3) and
random(3).
arc4random_buf() function fills the region buf of length nbytes with ARC4-derived random data.
arc4random_uniform() 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.
The arc4random_stir() function reads data from /dev/urandom and uses it to permute the S-Boxes via
arc4random_addrandom().
There is no need to call arc4random_stir() before using arc4random() functions family, since they auto-matically automatically
matically initialize themselves.
翻译: 具体翻译自己Google去,这里只说部分
Objective-C 中有个arc4random(函数用来生成随机数且不需要种子但是这个
函数生成的随机数范围比较大,需要用取模的算法对随机值进行限制,有点麻烦。
其实Objective-C有个更方便的随机数函数arc4random_uniform(x),
可以用来产生0~(x-1)范围内的随机数,不需要再进行取模运算。
如果要生成1~x的随机数,可以这么写:arc4random_uniform(x)+1