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); + } ///@}