objective-c产生随机数

来源:互联网 发布:科讯cms漏洞 编辑:程序博客网 时间:2024/04/30 09:29

#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;


原创粉丝点击