COIN-OR::LEMON - Graph Library

Changeset 515:b9b3473327e3 in lemon-1.2 for lemon/random.h


Ignore:
Timestamp:
02/16/09 19:15:52 (11 years ago)
Author:
Alpar Juttner <alpar@…>
Branch:
default
Parents:
514:2eb5c8ca2c91 (diff), 482: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

Legend:

Unmodified
Added
Removed
  • lemon/random.h

    r482 r515  
    33 * This file is a part of LEMON, a generic C++ optimization library.
    44 *
    5  * Copyright (C) 2003-2008
     5 * Copyright (C) 2003-2009
    66 * Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport
    77 * (Egervary Research Group on Combinatorial Optimization, EGRES).
     
    541541    /// @{
    542542
    543     ///\name Initialization
    544     ///
    545     /// @{
    546 
    547543    /// \brief Default constructor
    548544    ///
     
    691687    }
    692688
    693     /// @}
    694 
    695     ///\name Uniform distributions
    696     ///
    697     /// @{
    698 
    699689    /// \brief Returns a random real number from the range [0, 1)
    700690    ///
     
    751741      return _random_bits::IntConversion<Number, Word>::convert(core);
    752742    }
    753 
    754     /// @}
    755743
    756744    unsigned int uinteger() {
     
    787775    ///\name Non-uniform distributions
    788776    ///
    789 
    790777    ///@{
    791778
    792     /// \brief Returns a random bool
     779    /// \brief Returns a random bool with given probability of true result.
    793780    ///
    794781    /// It returns a random bool with given probability of true result.
     
    797784    }
    798785
    799     /// Standard Gauss distribution
    800 
    801     /// Standard Gauss distribution.
     786    /// Standard normal (Gauss) distribution
     787
     788    /// Standard normal (Gauss) distribution.
    802789    /// \note The Cartesian form of the Box-Muller
    803790    /// transformation is used to generate a random normal distribution.
     
    812799      return std::sqrt(-2*std::log(S)/S)*V1;
    813800    }
    814     /// Gauss distribution with given mean and standard deviation
    815 
    816     /// Gauss distribution with given mean and standard deviation.
     801    /// Normal (Gauss) distribution with given mean and standard deviation
     802
     803    /// Normal (Gauss) distribution with given mean and standard deviation.
    817804    /// \sa gauss()
    818805    double gauss(double mean,double std_dev)
    819806    {
    820807      return gauss()*std_dev+mean;
     808    }
     809
     810    /// Lognormal distribution
     811
     812    /// Lognormal distribution. The parameters are the mean and the standard
     813    /// deviation of <tt>exp(X)</tt>.
     814    ///
     815    double lognormal(double n_mean,double n_std_dev)
     816    {
     817      return std::exp(gauss(n_mean,n_std_dev));
     818    }
     819    /// Lognormal distribution
     820
     821    /// Lognormal distribution. The parameter is an <tt>std::pair</tt> of
     822    /// the mean and the standard deviation of <tt>exp(X)</tt>.
     823    ///
     824    double lognormal(const std::pair<double,double> &params)
     825    {
     826      return std::exp(gauss(params.first,params.second));
     827    }
     828    /// Compute the lognormal parameters from mean and standard deviation
     829
     830    /// This function computes the lognormal parameters from mean and
     831    /// standard deviation. The return value can direcly be passed to
     832    /// lognormal().
     833    std::pair<double,double> lognormalParamsFromMD(double mean,
     834                                                   double std_dev)
     835    {
     836      double fr=std_dev/mean;
     837      fr*=fr;
     838      double lg=std::log(1+fr);
     839      return std::pair<double,double>(std::log(mean)-lg/2.0,std::sqrt(lg));
     840    }
     841    /// Lognormal distribution with given mean and standard deviation
     842
     843    /// Lognormal distribution with given mean and standard deviation.
     844    ///
     845    double lognormalMD(double mean,double std_dev)
     846    {
     847      return lognormal(lognormalParamsFromMD(mean,std_dev));
    821848    }
    822849
     
    924951    ///\name Two dimensional distributions
    925952    ///
    926 
    927953    ///@{
    928954
     
    941967      return dim2::Point<double>(V1,V2);
    942968    }
    943     /// A kind of two dimensional Gauss distribution
     969    /// A kind of two dimensional normal (Gauss) distribution
    944970
    945971    /// This function provides a turning symmetric two-dimensional distribution.
  • lemon/random.h

    r440 r515  
    7878#include <unistd.h>
    7979#else
    80 #include <windows.h>
     80#include <lemon/bits/windows.h>
    8181#endif
    8282
     
    663663      seed(getpid() + tv.tv_sec + tv.tv_usec);
    664664#else
    665       FILETIME time;
    666       GetSystemTimeAsFileTime(&time);
    667       seed(GetCurrentProcessId() + time.dwHighDateTime + time.dwLowDateTime);
     665      seed(bits::getWinRndSeed());
    668666#endif
    669667      return true;
Note: See TracChangeset for help on using the changeset viewer.