# Changeset 392:80ec623f529f in lemon for lemon/random.h

Ignore:
Timestamp:
11/11/08 11:25:57 (15 years ago)
Branch:
default
Parents:
390:4b2382fd80ef (diff), 391:c4aa9f097ef1 (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the (diff) links above to see all the changes relative to each parent.
Phase:
public
Message:

Merge

Files:
2 edited

Unmodified
Removed
• ## lemon/random.h

 r352 } /// \brief Returns a random real number the range [0, b) /// /// It returns a random real number from the range [0, b). template Number real(Number b) { return real() * b; } /// \brief Returns a random real number from the range [a, b) /// /// It returns a random real number from the range [a, b). template Number real(Number a, Number b) { return real() * (b - a) + a; } /// \brief Returns a random real number from the range [0, 1) /// /// /// It returns a random real number from the range [0, b). template Number operator()(Number b) { return real() * b; double operator()(double b) { return real() * b; } /// /// It returns a random real number from the range [a, b). template Number operator()(Number a, Number b) { return real() * (b - a) + a; double operator()(double a, double b) { return real() * (b - a) + a; }
• ## lemon/random.h

 r391 /// @{ ///\name Initialization /// /// @{ /// \brief Default constructor /// } /// @} ///\name Uniform distributions /// /// @{ /// \brief Returns a random real number from the range [0, 1) /// return _random_bits::IntConversion::convert(core); } /// @} unsigned int 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. } /// Standard Gauss distribution /// Standard Gauss distribution. /// Standard normal (Gauss) distribution /// Standard normal (Gauss) distribution. /// \note The Cartesian form of the Box-Muller /// transformation is used to generate a random normal distribution. return std::sqrt(-2*std::log(S)/S)*V1; } /// Gauss distribution with given mean and standard deviation /// Gauss distribution with given mean and standard deviation. /// Normal (Gauss) distribution with given mean and standard deviation /// Normal (Gauss) distribution with given mean and standard deviation. /// \sa gauss() double gauss(double mean,double std_dev) { return gauss()*std_dev+mean; } /// Lognormal distribution /// Lognormal distribution. The parameters are the mean and the standard /// deviation of exp(X). /// double lognormal(double n_mean,double n_std_dev) { return std::exp(gauss(n_mean,n_std_dev)); } /// Lognormal distribution /// Lognormal distribution. The parameter is an std::pair of /// the mean and the standard deviation of exp(X). /// double lognormal(const std::pair ¶ms) { return std::exp(gauss(params.first,params.second)); } /// Compute the lognormal parameters from mean and standard deviation /// This function computes the lognormal parameters from mean and /// standard deviation. The return value can direcly be passed to /// lognormal(). std::pair lognormalParamsFromMD(double mean, double std_dev) { double fr=std_dev/mean; fr*=fr; double lg=std::log(1+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)); } ///\name Two dimensional distributions /// ///@{ 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.
Note: See TracChangeset for help on using the changeset viewer.