/ Published in: C++
Expand |
Embed | Plain Text
Copy this code and paste it in your HTML
class ContinuousRand { public: double alpha, x; boost::mt19937 gen; boost::uniform_smallint<> dst; boost::variate_generator< boost::mt19937,boost::uniform_smallint<> > rand; ContinuousRand(double _alpha): alpha(_alpha), x(0), gen( static_cast<unsigned long>(std::time(0)) ), dst(0,1), rand( gen, dst ) {} double operator()(){ x += (static_cast<double>(rand())-0.5)*2.0; x *= 1.0 - 1.0/alpha; return x/sqrt(alpha); } };