COIN-OR::LEMON - Graph Library

Ignore:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • lemon/random.h

    r62 r92  
    6868
    6969#include <ctime>
    70 #include <cmath>
    71 
     70
     71#include <lemon/math.h>
    7272#include <lemon/dim2.h>
     73
    7374///\ingroup misc
    7475///\file
     
    760761      double xi,nu;
    761762      const double delta = k-std::floor(k);
    762       const double v0=M_E/(M_E-delta);
     763      const double v0=E/(E-delta);
    763764      do {
    764765        double V0=1.0-real<double>();
     
    803804    } 
    804805     
     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     
    805829    ///@}
    806830   
Note: See TracChangeset for help on using the changeset viewer.