便宜又开朗的rand()更换 [英] Cheap and cheerful rand() replacement

查看:51
本文介绍了便宜又开朗的rand()更换的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在分析大型游戏程序后,我发现库函数rand()消耗了总处理时间的相当一部分.我对随机数生成器的要求不是很繁重-它通过大量的纯随机性统计测试并不重要.我只想要便宜又快的东西,而且很快.有什么建议吗?

After profiling a large game playing program, I have found that the library function rand() is consuming a considerable fraction of the total processing time. My requirements for the random number generator are not very onerous - its not important that it pass a great battery of statistical tests of pure randomness. I just want something cheap and cheerful that is very fast. Any suggestions?

推荐答案

很少有比 Xorshift 生成器,该生成器非常快(取决于硬件). WELL512a 生成器也相当快(比MT19937或MT19937-64还快) ).

There are few algorithms in common use that are faster than an LCG (which is very, very likely what rand() is using). You may want to try Marsaglia's Xorshift generator which is pretty fast (depending on the hardware). The WELL512a generator is also quite fast (more so than MT19937 or MT19937-64).

这篇关于便宜又开朗的rand()更换的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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