#ifndef __BOOST_RNG__ #define __BOOST_RNG__ #include #include #include namespace math { namespace rng { /*! * \class normal_generator * \brief This class is basic normal random number generator \n * template id RealType describe number precision (float double ....)\n * template id PRNG describe pseudo random number generator ( see boost random) */ template < class RealType , class PRNG > class normal_generator { public : /*! * Default construtor */ normal_generator(): engine(time(NULL)), generator(engine,boost::normal_distribution(0,1)) {} /*! * Construtor * \param dist : a normal distribution (see boost distributions) */ normal_generator(const boost::math::normal_distribution & dist): engine(time(NULL)), generator(engine,boost::normal_distribution(dist.mean(),dist.sigma())) {} /*! * Construtor * \param mean : mean of the normal distribution * \param sigma : satndard deviation of the normal distribution */ normal_generator(const RealType & mean ,const RealType & sigma): engine(time(NULL)), generator(engine,boost::normal_distribution(mean(),sigma())) {} /*! * Get a random number */ RealType operator()() {return generator();} /*! * Set normal distribution * \param dist : a normal distribution (see boost distributions) */ void distribution( const boost::math::normal_distribution & dist) { generator.dist= boost::normal_distribution(dist.mean(),dist.standard_deviation()); } /*! * Set normal distrubution * \param mean : mean of the normal distribution * \param sigma : satndard deviation of the normal distribution */ void distribution( const RealType & mean ,const RealType & sigma) { generator.distribution()= boost::normal_distribution(mean,sigma); } private : /*! * \brief pseudo random number generator */ PRNG engine; /*! * \brief the normal random number generator */ boost::variate_generator > generator; }; typedef class normal_generator normal_rng; /*! * \class uniform_generator * \brief This class is basic uniform random number generator \n * template id RealType describe number precision (float double ....)\n * template id PRNG describe pseudo random number generator ( see boost random) */ template < class RealType , class PRNG > class uniform_generator { public : /*! * Default construtor */ uniform_generator(): engine(time(NULL)), generator(engine, boost::uniform_real(0,1)) {} /*! * Construtor * \param dist : a uniform distribution (see boost distributions) */ uniform_generator(const boost::math::uniform_distribution & dist): engine(time(NULL)), generator(engine, boost::uniform_real(dist.lower(),dist.upper())) {} /*! * Construtor * \param lower : the lower value of the uniform distribution * \param upper : the upper value of the uniform distribution */ uniform_generator(const RealType & lower , const RealType & upper): engine(time(NULL)), generator(engine, boost::uniform_real(lower,upper)) {} /*! * Get a random number */ RealType operator()() {return generator();} /*! * Set uniform distribution * \param dist : a normal distribution (see boost distributions) */ void distribution( const boost::math::uniform_distribution & dist) { generator.dist()= boost::uniform_real(dist.lower(),dist.upper()); } /*! * Set uniform distribution * \param lower : the lower value of the uniform distribution * \param upper : the upper value of the uniform distribution */ void distribution( const RealType & lower , const RealType & upper) { generator.dist()= boost::uniform_real(lower,upper); } private : /*! * \brief pseudo random number generator */ PRNG engine; /*! * \brief the uniform random number generator */ boost::variate_generator > generator; }; typedef class uniform_generator uniform_rng; /*! * \class traingle_generator * \brief This class is basic triangular random number generator \n * template id RealType describe number precision (float double ....)\n * template id PRNG describe pseudo random number generator ( see boost random) */ template < class RealType , class PRNG > class triangle_generator { public : /*! * Default construtor */ triangle_generator(): engine(time(NULL)), generator(engine, boost::triangle_distribution(-1,0,1)) {} /*! * Construtor * \param dist : a traingle distribution (see boost distributions) */ triangle_generator(const boost::math::triangular_distribution & dist): engine(time(NULL)), generator(engine, boost::triangle_distribution(dist.lower(),dist.upper())) {} /*! * Constructor : * \param lower : the lower value of the uniform distribution * \param mode : the mode value of the uniform distribution * \param upper : the upper value of the uniform distribution */ triangle_generator(const RealType & lower , const RealType & mode ,const RealType & upper): engine(time(NULL)), generator(engine, boost::triangle_distribution(lower,mode,upper)) {} /*! * Get a random number */ RealType operator()() {return generator();} /*! * Set triangle distribution * \param dist : a normal distribution (see boost distributions) */ void distribution( const boost::math::triangular_distribution & dist) { generator.dist()= boost::triangle_distribution(dist.lower(),dist.mode(),dist.upper()); } /*! * Set triangle distribution * \param lower : the lower value of the uniform distribution * \param mode : the mode value of the uniform distribution * \param upper : the upper value of the uniform distribution */ void distribution( const RealType & lower ,const RealType & mode ,const RealType & upper) { generator.dist()= boost::triangle_distribution(lower,mode,upper); } private : /*! * \brief pseudo random number generator */ PRNG engine; /*! * \brief the triangle random number generator */ boost::variate_generator > generator; }; typedef class triangle_generator triangle_rng; }; }; #endif