什么是游戏的好的随机数生成器? [英] What is a good random number generator for a game?

查看:34
本文介绍了什么是游戏的好的随机数生成器?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在 C++ 中用于游戏的好的随机数生成器是什么?

我的考虑是:

  1. 需要大量随机数,所以速度不错.
  2. 玩家总是会抱怨随机数,但我希望能够向他们指出一个参考资料,说明我确实做到了我的工作.
  3. 由于这是一个我没有太多时间参与的商业项目,如果算法 a) 相对容易实现或 b) 有一个很好的非 GPL 实现可用,那就太好了.
  4. 我已经在很多地方使用了 rand(),所以任何其他生成器最好能证明它需要的所有更改是合理的.

我对这个主题不太了解,所以我能想到的唯一选择是 Mersenne捻线机;它是否满足所有这些要求?还有什么更好的吗?

Mersenne Twister 似乎是共识选择.但是第 4 点呢?它真的比 rand() 好很多吗?

编辑 2: 让我更清楚地说明第 2 点:玩家无法通过知道随机数来作弊.时期.我希望它足够随机,以至于人们(至少那些了解随机性的人)不会抱怨它,但我并不担心预测.这就是为什么我把速度作为首要考虑因素.

编辑 3:我现在倾向于 Marsaglia RNG,但我仍然希望获得更多的输入.因此,我正在设置赏金.

编辑 4: 请注意:我打算在今天 UTC 午夜之前接受一个答案(以避免弄乱某人的代表上限).因此,如果您正在考虑回答,请不要等到最后一刻!
另外,我喜欢 Marsaglia 的 XORshift 生成器的外观.有人对他们有任何意见吗?

解决方案

George Marsaglia 有开发了一些目前可用的最好和最快的 RNGMultiply-with-carry 是一个值得注意的均匀分布.>

=== 更新 2018-09-12 ===

对于我自己的工作,我现在使用 Xoshiro256**,这是对 Marsaglia 的 XorShift 的一种进化/更新.

=== 更新 2021-02-23 ===

在 .NET 6(目前为预览版)中,System.Random 的实现已更改为使用 xoshiro256**,但仅适用于无参数构造函数.采用种子的构造函数使用旧的 PRNG 以保持向后兼容性.有关详细信息,请参阅提高随机性(性能、API 等)

What is a good random number generator to use for a game in C++?

My considerations are:

  1. Lots of random numbers are needed, so speed is good.
  2. Players will always complain about random numbers, but I'd like to be able to point them to a reference that explains that I really did my job.
  3. Since this is a commercial project which I don't have much time for, it would be nice if the algorithm either a) was relatively easy to implement or b) had a good non-GPL implementation available.
  4. I'm already using rand() in quite a lot of places, so any other generator had better be good to justify all the changes it would require.

I don't know much about this subject, so the only alternative I could come up with is the Mersenne Twister; does it satisfy all these requirements? Is there anything else that's better?

Edit: Mersenne Twister seems to be the consensus choice. But what about point #4? Is it really that much better than rand()?

Edit 2: Let me be a little clearer on point 2: There is no way for players to cheat by knowing the random numbers. Period. I want it random enough that people (at least those who understand randomness) can't complain about it, but I'm not worried about predictions. That's why I put speed as the top consideration.

Edit 3: I'm leaning toward the Marsaglia RNGs now, but I'd still like more input. Therefore, I'm setting up a bounty.

Edit 4: Just a note: I intend to accept an answer just before midnight UTC today (to avoid messing with someone's rep cap). So if you're thinking of answering, don't wait until the last minute!
Also, I like the looks of Marsaglia's XORshift generators. Does anyone have any input about them?

解决方案

George Marsaglia has developed some of the best and fastest RNGs currently available Multiply-with-carry being a notable one for a uniform distribution.

=== Update 2018-09-12 ===

For my own work I'm now using Xoshiro256**, which is a sort of evolution/update on Marsaglia's XorShift.

=== Update 2021-02-23 ===

In .NET 6 (currently in preview) the implementation of System.Random has been changed to use xoshiro256**, but only for the parameterless constructor. The constructor that takes a seed uses the old PRNG in order to maintain backwards compatibility. For more info see Improve Random (performance, APIs, ...)

这篇关于什么是游戏的好的随机数生成器?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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