is there a way to set independent random streams in c++ using the armadillo c++ library? -
i want 2 independent random streams armadillo rand library. seems both use same global random stream.
i can generate random numbers using armadillo library via following:
arma::arma_rng::set_seed(13) double r = arma::randu()
but not sure how 2 random streams. in python know can following using random library numpy:
rn = random.randomstate(13) rn2 = random.randomstate(11)
now if run rn.rand() , rn2.rand() independent , don't effect 1 another. ideas?
thanks!
independent random number generators can used in conjunction .imbue() function in armadillo.
the code below adapted armadillo documentation. c++11 compiler required use std::mt19937
, std::uniform_real_distribution
.
std::mt19937 engine1; // mersenne twister random number engine std::mt19937 engine2; // ... set seeds engine1 , engine2 here ... std::uniform_real_distribution<double> distr(0.0, 1.0); mat a(4,5); mat b(4,10); a.imbue( [&]() { return distr(engine1); } ); b.imbue( [&]() { return distr(engine2); } );
more info on mersenne engine: http://en.cppreference.com/w/cpp/numeric/random/mersenne_twister_engine
more info on std::uniform_real_distribution: http://en.cppreference.com/w/cpp/numeric/random/uniform_real_distribution
Comments
Post a Comment