我需要在我的iPhone游戏中生成随机数 我使用rand()函数 但是它不够随机 我试过用srand但是我的随机发生器是周期性的 /dev/random不是答案,因为我需要0.1秒的新随机数srand(time(null))on iPhone does not work =(
0
A
回答
4
在iOS和OS X上,改为使用arc4random。质量随机性更高,无需担心播种。
但是,rand()
不应该是周期性的,除非您每次打电话srand
。或者错误地使用随机数字。
3
你可以试试random()/ srandom()来代替。比rand()/ srand()更好的发生器。
0
你是为了调试还是在模拟器上构建?我知道我在调试时构建了一些Windows应用程序时遇到了这种问题, RNG自动采用恒定值进行播种,以产生一致的结果。您可能想要检查实际播种的内容,以及每次运行时是否获得不同的输出。
相关问题
- 1. ajax jquery does not work on ie
- 2. Jquery $ .post does not work on chrome
- 3. Html.ClientValidation does not work on mvc
- 4. ellipsize on textview does not work
- 5. if(pause == null){does not work
- 6. does find_under_expand_skip does not work on mac sublime?
- 7. dojo does not work on worklight application on IE
- 8. display:none does not work
- 9. RequestMapping does not work
- 10. response.redirect does not work
- 11. mysql query does not work
- 12. fscanf does not work properly
- 13. android asynctask does not work
- 14. requiredFieldError does not work
- 15. Score ++ does not work
- 16. Intent.EXTRA_LOCAL_ONLY does not work
- 17. InAppPurchase does not work
- 18. Var_dump does not work
- 19. document.body.style.backgroundImage does not work
- 20. WIthMockUser does not work
- 21. httpwebresponse does not work
- 22. Iframe does not work
- 23. Meteor.subscribe does not work
- 24. $(document).ready does not work
- 25. recyclerview addOnScrollListener does not work
- 26. onKeyPress does not Work At Work!
- 27. PlayFramework 2.2 does not work on Mac os X mavericks
- 28. jquery“contains”code does not work on chrome
- 29. chai-smoothie:to.eventually.be.displayed on a function does not work?
- 30. textarea maxlength does not work on enter key press
arc4random()使用/ dev/random作为源。 – JustSid 2011-05-06 14:33:26
是的。我每次都打电话给srand()。 =(我认为它可以解决rand()的问题 – Riddick 2011-05-06 14:35:38
@JustSid:arc4random对* seed *使用'/ dev/urandom'(而不是'/ dev/random'),当你手动调用arc4random_stir时。 – Anomie 2011-05-06 14:37:41