srand(time(null)) on iPhone don't work =(

你说的曾经没有我的故事 提交于 2019-12-02 12:34:57

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

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

You could try random() / srandom() instead. Better generator than rand() / srand().

Are you building for debug or on the simulator? I know I ran into this kind of issue when building some windows applications in debug, the RNG was automatically seeded with a constant value to produce consistent results. You may want to check what it is actually seeded with, and if you are getting different outputs at all each run.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!