diff -r 99e499ca560b -r ea5945b2da9c lemon/random.h --- a/lemon/random.h Fri Dec 21 00:07:03 2007 +0000 +++ b/lemon/random.h Fri Dec 21 01:32:24 2007 +0000 @@ -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); + } ///@}