现在的位置: 首页 > 综合 > 正文

objective-c产生随机数

2019年10月01日 ⁄ 综合 ⁄ 共 395字 ⁄ 字号 评论关闭

#include <stdlib.h>
 u_int32_t  arc4random(void);

The arc4random() function uses the key stream generator employed by the arc4 cipher, which uses 8*8 8bit 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().

arc4random() 可以替代传统的rand(), random(), 返回类型是u_int32_t,不需要srand()去生成种子

//可以产生0 ~ 99的随机数
int index = arc4random() %100;

抱歉!评论已关闭.