lemon/random.h
changeset 93 f857981306ea
parent 68 a315a588a20d
child 102 81563e019fa4
equal deleted inserted replaced
8:c0a706ad07c4 9:0b481549ff48
   801     double pareto(double k,double x_min)
   801     double pareto(double k,double x_min)
   802     {
   802     {
   803       return exponential(gamma(k,1.0/x_min));
   803       return exponential(gamma(k,1.0/x_min));
   804     }  
   804     }  
   805       
   805       
       
   806     /// Poisson distribution
       
   807 
       
   808     /// This function generates a Poisson distribution random number with
       
   809     /// parameter \c lambda.
       
   810     /// 
       
   811     /// The probability mass function of this distribusion is
       
   812     /// \f[ \frac{e^{-\lambda}\lambda^k}{k!} \f]
       
   813     /// \note The algorithm is taken from the book of Donald E. Knuth titled
       
   814     /// ''Seminumerical Algorithms'' (1969). Its running time is linear in the
       
   815     /// return value.
       
   816     
       
   817     int poisson(double lambda)
       
   818     {
       
   819       const double l = std::exp(-lambda);
       
   820       int k=0;
       
   821       double p = 1.0;
       
   822       do {
       
   823 	k++;
       
   824 	p*=real<double>();
       
   825       } while (p>=l);
       
   826       return k-1;
       
   827     }  
       
   828       
   806     ///@}
   829     ///@}
   807     
   830     
   808     ///\name Two dimensional distributions
   831     ///\name Two dimensional distributions
   809     ///
   832     ///
   810 
   833