iPhone:random()函数每次给我相同的随机数 [英] iPhone: random() function gives me the same random number everytime
本文介绍了iPhone:random()函数每次给我相同的随机数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我使用函数random()%x来生成随机数,但每次启动应用程序时,我都会看到它创建或生成相同的数字。
I am using function random()%x for the generation of a random number, but every time I start the application I see that it creates or generates the same number.
就像我根据随机数随机放置一些图像一样,无论我运行应用程序多少次,我都会看到所有图像都放在同一个地方。 / p>
Like I am placing some images randomly based on that random number and I see all the images are placed at the same place no matter how many times I run the application.
推荐答案
你可能会有更好的运气 arc4random()
,你不需要明确地播种它,它似乎是一个更好的随机。
You'll likely have better luck with arc4random()
, you don't need to explicitly seed it and it seems to be a "better" random.
这篇关于iPhone:random()函数每次给我相同的随机数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文