# HG changeset patch # User Alpar Juttner # Date 2007-12-21 02:32:24 # Node ID ea5945b2da9c0b92a55d0b8e41c58c838842d8cc # Parent 99e499ca560bbac6de2f030a39e8f5809188e40f Pareto and Weibull random distributions diff --git a/lemon/random.h b/lemon/random.h --- a/lemon/random.h +++ b/lemon/random.h @@ -737,7 +737,7 @@ /// double exponential(double lambda=1.0) { - return -std::log(real())/lambda; + return -std::log(1.0-real())/lambda; } /// Gamma distribution with given integer shape @@ -782,6 +782,33 @@ return theta*(xi-gamma(int(std::floor(k)))); } + /// Weibull distribution + + /// This function generates a Weibull distribution random number. + /// + ///\param k shape parameter (k>0) + ///\param lambda scale parameter (lambda>0) + /// + double weibull(double k,double lambda) + { + return lambda*pow(-std::log(1.0-real()),1.0/k); + } + + /// Pareto distribution + + /// This function generates a Pareto distribution random number. + /// + ///\param x_min location parameter (x_min>0) + ///\param k shape parameter (k>0) + /// + ///\warning This function used inverse transform sampling, therefore may + ///suffer from numerical unstability. + /// + ///\todo Implement a numerically stable method + double pareto(double x_min,double k) + { + return x_min*pow(1.0-real(),1.0/k); + } ///@}