I want to generate N independent sets of random numbers in C++.
I tried with the std::random
, however I can do it only by declaring multiple default_random_engines. It works, but it does not suffice for my case because I do not know a priori the number of independent sets that I need.
It is important, because I need to know that each set of randomly generated numbers obeys the selected distribution, I cannot just use the same function for all of my numbers.
I would say you don't need multiple random engines, what you need is multiple distributions.
something like
std::default_random_engine generator;
std::uniform_real_distribution<double> distributionA(0.0,1.0);
std::uniform_real_distribution<double> distributionB(-1.0,2.0);
std::uniform_real_distribution<double> distributionC(-7.0,0.5);
and later do sampling
double a = distributionA(generator);
double b = distributionB(generator);
double c = distributionC(generator);
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.