Cocoa生成随机数
来源:互联网 发布:小米平板刷windows 编辑:程序博客网 时间:2024/06/10 06:24
You should use the arc4random() function. It uses a superior algorithm to rand. You don't even need to set a seed.
arc4random, arc4random_stir, arc4random_addrandom -- arc4 random number generator
Same as C, you would do
int r = rand() % 74; // [0, 74)
Feel free to substitute
random()
or arc4random()
for rand()
(which is, as others have pointed out, quite sucky).srandom((unsigned int)time(NULL)); // 防止出现警告
arc4random_uniform(74); // [0, 74)
arc4random_uniform(upper_bound)
avoids modulo bias as described in the man page:
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.
- Cocoa生成随机数
- cocoa 取随机数 随机数的使用
- 【随机数】生成随机数模板
- 生成随机数
- 随机数生成
- 随机数生成
- 生成随机数
- 生成随机数
- 生成随机数
- 随机数生成
- 随机数生成
- 生成随机数
- 生成随机数
- 随机数生成
- 随机数生成
- 生成随机数
- 生成随机数
- 随机数生成...
- 拷贝构造函数--内存被重复释放的隐形人
- maven简单使用简记
- 程序设计语言的分类
- Objective-C、C++以及C之间的区别
- 费波拿契(Fibonacci)数和阶乘
- Cocoa生成随机数
- Facebook老员工的十点经验
- levelDB源码分析-Log文件
- CALayer简单教程
- 使用Outlook Express在外贸B2C进行个性化邮件群发
- 路径分析,可以拖动上面的节点,动态修改(转帖自heyubingzju)
- mfc连接access数据库
- Adobe Dynamic Http Streaming的简单配置与实现 (FMS, HLS, HDS)
- 各种计算机控制系统特点小结