# Ticket #164: 0293cb1b9e9c.patch

File 0293cb1b9e9c.patch, 4.9 KB (added by Peter Kovacs, 14 years ago)
• ## lemon/random.h

# HG changeset patch
# User Peter Kovacs <kpeter@inf.elte.hu>
# Date 1225190621 -3600
# Node ID 0293cb1b9e9cc7d0a1f0dc1ef95a09ee07c732f5
# Parent  2593e163e407403990ba8f4323f684190a625a62
Add normal() as an alias for gauss() + doc improvements

diff --git a/lemon/random.h b/lemon/random.h
 a /// /// @{ ///\name Initialization /// /// @{ /// \brief Default constructor /// /// Constructor with constant seeding. return real() * (b - a) + a; } /// @} ///\name Uniform distributions /// /// @{ /// \brief Returns a random real number from the range [0, 1) /// /// It returns a random double from the range [0, 1). return _random_bits::IntConversion::convert(core); } /// @} unsigned int uinteger() { return uinteger(); } ///\name Non-uniform distributions /// ///@{ /// \brief Returns a random bool /// \brief Returns a random bool with given probability of true result. /// /// It returns a random bool with given probability of true result. bool boolean(double p) { return operator()() < p; } /// Standard Gauss distribution /// Standard normal (Gauss) distribution /// Standard Gauss distribution. /// Standard normal (Gauss) distribution. /// \note The Cartesian form of the Box-Muller /// transformation is used to generate a random normal distribution. double gauss() double normal() { double V1,V2,S; do { } while(S>=1); return std::sqrt(-2*std::log(S)/S)*V1; } /// Gauss distribution with given mean and standard deviation /// Normal (Gauss) distribution with given mean and standard deviation /// Gauss distribution with given mean and standard deviation. /// \sa gauss() /// Normal (Gauss) distribution with given mean and standard deviation. /// \sa normal() double normal(double mean,double std_dev) { return normal()*std_dev+mean; } /// Standard normal (Gauss) distribution /// Standard normal (Gauss) distribution. /// /// It is an alias for \ref normal(). double gauss() { return normal(); } /// Normal (Gauss) distribution with given mean and standard deviation /// Normal (Gauss) distribution with given mean and standard deviation. /// /// It is an alias for \ref normal(double, double). double gauss(double mean,double std_dev) { return gauss()*std_dev+mean; return normal(mean,std_dev); } /// Lognormal distribution /// standard deviation. The return value can direcly be passed to /// lognormal(). std::pair lognormalParamsFromMD(double mean, double std_dev) double std_dev) { double fr=std_dev/mean; fr*=fr; return std::pair(std::log(mean)-lg/2.0,std::sqrt(lg)); } /// Lognormal distribution with given mean and standard deviation /// Lognormal distribution with given mean and standard deviation. /// double lognormalMD(double mean,double std_dev) { return lognormal(lognormalParamsFromMD(mean,std_dev)); } /// Exponential distribution with given mean /// This function generates an exponential distribution random number ///\name Two dimensional distributions /// ///@{ /// Uniform distribution on the full unit circle } while(V1*V1+V2*V2>=1); return dim2::Point(V1,V2); } /// A kind of two dimensional Gauss distribution /// A kind of two dimensional normal (Gauss) distribution /// This function provides a turning symmetric two-dimensional distribution. /// Both coordinates are of standard normal distribution, but they are not /// /// \note The coordinates are the two random variables provided by /// the Box-Muller method. dim2::Point gauss2() dim2::Point normal2() { double V1,V2,S; do { double W=std::sqrt(-2*std::log(S)/S); return dim2::Point(W*V1,W*V2); } /// A kind of two dimensional normal (Gauss) distribution /// A kind of two dimensional normal (Gauss) distribution. /// /// It is an alias for \ref normal2(). dim2::Point gauss2() { return normal2(); } /// A kind of two dimensional exponential distribution /// This function provides a turning symmetric two-dimensional distribution.