# Changeset 492:b9b3473327e3 in lemon-main for lemon/random.h

Ignore:
Timestamp:
02/16/09 19:15:52 (13 years ago)
Branch:
default
Parents:
490:2eb5c8ca2c91 (diff), 491:879c55700cd4 (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
Added
Removed
• ## lemon/random.h

 r440 #include #else #include #include #endif seed(getpid() + tv.tv_sec + tv.tv_usec); #else FILETIME time; GetSystemTimeAsFileTime(&time); seed(GetCurrentProcessId() + time.dwHighDateTime + time.dwLowDateTime); seed(bits::getWinRndSeed()); #endif return true;
• ## lemon/random.h

 r491 * This file is a part of LEMON, a generic C++ optimization library. * * Copyright (C) 2003-2008 * Copyright (C) 2003-2009 * Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport * (Egervary Research Group on Combinatorial Optimization, EGRES). /// @{ ///\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.