// std::mt19937 random number generator // uses std::function and std::bind #include #include #include #include #include using namespace std; // define generator std::mt19937 gener; 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(0,1); rnd = bind(unif, gener); first = false; } return rnd(); } double gaussrand(void){ static bool first = true; static function rnd ; if(first) { initrng(); normal_distribution gaussian(0,1); rnd = bind(gaussian, gener); first = false; } return rnd(); } double exprand(void){ static bool first = true; static function rnd ; if(first) { initrng(); exponential_distribution expo; rnd = bind(expo, gener); first = false; } return rnd(); }