lemon/random.h
changeset 479 55111a054b2e
parent 280 e7f8647ce760
child 378 80ec623f529f
child 482 879c55700cd4
equal deleted inserted replaced
16:fc290b6cc30f 19:95cf46ca15fa
   690 
   690 
   691     double real() {
   691     double real() {
   692       return real<double>();
   692       return real<double>();
   693     }
   693     }
   694 
   694 
   695     /// \brief Returns a random real number the range [0, b)
       
   696     ///
       
   697     /// It returns a random real number from the range [0, b).
       
   698     template <typename Number>
       
   699     Number real(Number b) {
       
   700       return real<Number>() * b;
       
   701     }
       
   702 
       
   703     /// \brief Returns a random real number from the range [a, b)
       
   704     ///
       
   705     /// It returns a random real number from the range [a, b).
       
   706     template <typename Number>
       
   707     Number real(Number a, Number b) {
       
   708       return real<Number>() * (b - a) + a;
       
   709     }
       
   710 
       
   711     /// @}
   695     /// @}
   712 
   696 
   713     ///\name Uniform distributions
   697     ///\name Uniform distributions
   714     ///
   698     ///
   715     /// @{
   699     /// @{
   722     }
   706     }
   723 
   707 
   724     /// \brief Returns a random real number from the range [0, b)
   708     /// \brief Returns a random real number from the range [0, b)
   725     ///
   709     ///
   726     /// It returns a random real number from the range [0, b).
   710     /// It returns a random real number from the range [0, b).
   727     template <typename Number>
   711     double operator()(double b) {
   728     Number operator()(Number b) {
   712       return real<double>() * b;
   729       return real<Number>() * b;
       
   730     }
   713     }
   731 
   714 
   732     /// \brief Returns a random real number from the range [a, b)
   715     /// \brief Returns a random real number from the range [a, b)
   733     ///
   716     ///
   734     /// It returns a random real number from the range [a, b).
   717     /// It returns a random real number from the range [a, b).
   735     template <typename Number>
   718     double operator()(double a, double b) {
   736     Number operator()(Number a, Number b) {
   719       return real<double>() * (b - a) + a;
   737       return real<Number>() * (b - a) + a;
       
   738     }
   720     }
   739 
   721 
   740     /// \brief Returns a random integer from a range
   722     /// \brief Returns a random integer from a range
   741     ///
   723     ///
   742     /// It returns a random integer from the range {0, 1, ..., b - 1}.
   724     /// It returns a random integer from the range {0, 1, ..., b - 1}.