// std::mt19937 random number generator // uses std::function and std::bind #include #include #include #include #include using namespace std; std::mt19937 gener; // define generator void initrng(void){ static bool first = true; if(first){ auto seed = static_cast (std::time(0)); cout<<" seed = "< rnd ; if(first){ initrng(); uniform_real_distribution unif_dist(0,1); rnd = bind(unif_dist, gener); first = false; } return rnd(); } double gaussrand(void){ static bool first = true; static function rnd ; if(first) { initrng(); normal_distribution norm_dist(0,1); rnd = bind(norm_dist, gener); first = false; } return rnd(); } double gaussrand2(void){ // warning: does not initialize generator static normal_distribution norm_dist(0,1); return (norm_dist(gener)); } double exprand(void){ static bool first = true; static function rnd ; if(first) { initrng(); exponential_distribution expo; rnd = bind(expo, gener); first = false; } return rnd(); }