I need to use normal and uniform distributed random numbers in my class. I want to set the seed in the main function and then give it over to the class, so that every random number is different during the whole process
But i do something totally wrong, because as soon as the public function calls the private function, there are the same random values:
class Dist{
public:
Dist(boost::random::mt19937& rng_, ...)
: rng(rng_){..}
void operator()(const int timesteps){
for(int i=0; i<timesteps; ++i){
onestep();
}
...
}
private:
double N(boost::random::mt19937& rng_){
boost::normal_distribution<> nd(0.0, 1.0);
boost::variate_generator<boost::mt19937&,
boost::normal_distribution<> > var_nor(rng_, nd);
double d;
return d= var_nor();
}
double unix(boost::random::mt19937& rng_){
boost::random::uniform_real_distribution<> uni_x(-dw,0.0);
double x;
return x=uni_x(rng_);
}
void onestep(){
for(int i=0; i<nr; ++i){
double Yx = unix(rng);
double Yy = uniy(rng);
Y_res.push_back({Yx,Yy});
}
...
...
};
Now everytime i call the function onestep with the operator(), the vector Y_res is exactly the same. What do i wrong?
Aucun commentaire:
Enregistrer un commentaire