简体   繁体   中英

Random number distributions c++11

I have a program that uses several distribution objects:

Like:

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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