简体   繁体   English

随机数分布C ++ 11

[英]Random number distributions c++11

I have a program that uses several distribution objects: 我有一个使用多个分发对象的程序:

Like: 喜欢:

std::normal_distribution std::exponential_distribution std :: normal_distribution std :: exponential_distribution

etc.. 等等..

Should I use a random number engine for each one, or should make all of them share a same generator? 我应该为每个引擎使用一个随机数引擎,还是应该让它们全部共享同一个生成器?

Usually you want every instantiation of a distribution to represent an uncorrelated stochastic variable, which means that you should a new engine for each one. 通常,您希望分布的每个实例都代表一个不相关的随机变量,这意味着您应该为每个变量创建一个新引擎。 Should your stochastic variables be correlated, you should rather introduce the correlation yourself instead of reusing a random engine, so that you can ensure it is correctly modeled. 如果您的随机变量具有相关性,那么您应该自己引入相关性,而不是重复使用随机引擎,这样可以确保已正确建模。

Sometimes, you can cheat a tiny bit by seeding only a single (and used only for this) random engine and use that to seed the other random engines. 有时,您可以通过仅播种单个(仅用于此)随机引擎,并使用其播种其他随机引擎来作弊。

Should you not care about ensuring that your stochastic variables are uncorrelated (eg you are not doing any scientific work, but programming a game) you may ignore this, since it usually does not matter. 如果您不关心确保随机变量不相关(例如,您没有做任何科学工作,而是在编写游戏程序),则可以忽略这一点,因为通常这并不重要。

The usual answer is, of course, it depends. 当然,通常的答案取决于情况。

If you're trying to do simulation work and will be pulling lots of random numbers, it's better to use a different engine for each. 如果您要进行仿真工作并且会提取大量随机数,则最好为每个引擎使用不同的引擎。 Otherwise, it doesn't much matter. 否则,没什么大不了的。

There is no reason to use multiple engines. 没有理由使用多个引擎。 If you are going to draw A LOT of random numbers and you think the results will seem correlated, change the engine to one with bigger cycle length. 如果要绘制大量随机数,并且您认为结果似乎相关,请将引擎更改为周期长度更大的引擎。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM