iPhone上的srand(time(null))不起作用=( [英] srand(time(null)) on iPhone don't work =(

查看:87
本文介绍了iPhone上的srand(time(null))不起作用=(的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要在我的iPhone游戏中生成随机数. 我使用rand()函数. 但这还不够随机. 我尝试将srand与time(Null)一起使用. 但是我的随机生成器是周期性的. /dev/random不能解决问题,因为我每0.1秒需要一个新的随机数.

I need generate random numbers in my iPhone game. I using rand() function. But it isn't enough random. I tried using srand with time(Null). But my random generator was periodic. /dev/random isn't an answer because I need new random number each 0.1 sec.

推荐答案

在iOS和OS X上,使用

On iOS and OS X, use arc4random instead. Higher quality randomness, and no need to worry about seeding.

但是,除非您每次都调用srand,否则rand()不应是周期性的.或错误地使用了随机数.

However, rand() shouldn't be noticably periodic, unless you're calling srand each time around. Or using the random numbers incorrectly.

这篇关于iPhone上的srand(time(null))不起作用=(的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆