lemon/random.h
changeset 390 53c5277ba294
parent 340 0badf3bb38c2
parent 377 c4aa9f097ef1
child 440 88ed40ad0d4f
equal deleted inserted replaced
18:8034abbbcfca 20:f2e919fd2ef6
   686 
   686 
   687     double real() {
   687     double real() {
   688       return real<double>();
   688       return real<double>();
   689     }
   689     }
   690 
   690 
   691     /// \brief Returns a random real number the range [0, b)
       
   692     ///
       
   693     /// It returns a random real number from the range [0, b).
       
   694     template <typename Number>
       
   695     Number real(Number b) {
       
   696       return real<Number>() * b;
       
   697     }
       
   698 
       
   699     /// \brief Returns a random real number from the range [a, b)
       
   700     ///
       
   701     /// It returns a random real number from the range [a, b).
       
   702     template <typename Number>
       
   703     Number real(Number a, Number b) {
       
   704       return real<Number>() * (b - a) + a;
       
   705     }
       
   706 
       
   707     /// \brief Returns a random real number from the range [0, 1)
   691     /// \brief Returns a random real number from the range [0, 1)
   708     ///
   692     ///
   709     /// It returns a random double from the range [0, 1).
   693     /// It returns a random double from the range [0, 1).
   710     double operator()() {
   694     double operator()() {
   711       return real<double>();
   695       return real<double>();
   712     }
   696     }
   713 
   697 
   714     /// \brief Returns a random real number from the range [0, b)
   698     /// \brief Returns a random real number from the range [0, b)
   715     ///
   699     ///
   716     /// It returns a random real number from the range [0, b).
   700     /// It returns a random real number from the range [0, b).
   717     template <typename Number>
   701     double operator()(double b) {
   718     Number operator()(Number b) {
   702       return real<double>() * b;
   719       return real<Number>() * b;
       
   720     }
   703     }
   721 
   704 
   722     /// \brief Returns a random real number from the range [a, b)
   705     /// \brief Returns a random real number from the range [a, b)
   723     ///
   706     ///
   724     /// It returns a random real number from the range [a, b).
   707     /// It returns a random real number from the range [a, b).
   725     template <typename Number>
   708     double operator()(double a, double b) {
   726     Number operator()(Number a, Number b) {
   709       return real<double>() * (b - a) + a;
   727       return real<Number>() * (b - a) + a;
       
   728     }
   710     }
   729 
   711 
   730     /// \brief Returns a random integer from a range
   712     /// \brief Returns a random integer from a range
   731     ///
   713     ///
   732     /// It returns a random integer from the range {0, 1, ..., b - 1}.
   714     /// It returns a random integer from the range {0, 1, ..., b - 1}.