Changes in lemon/random.h [92:5d4decd1b870:68:a315a588a20d] in lemon-1.0
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
lemon/random.h
r92 r68 804 804 } 805 805 806 /// Poisson distribution807 808 /// This function generates a Poisson distribution random number with809 /// parameter \c lambda.810 ///811 /// The probability mass function of this distribusion is812 /// \f[ \frac{e^{-\lambda}\lambda^k}{k!} \f]813 /// \note The algorithm is taken from the book of Donald E. Knuth titled814 /// ''Seminumerical Algorithms'' (1969). Its running time is linear in the815 /// 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 829 806 ///@} 830 807
Note: See TracChangeset
for help on using the changeset viewer.