Changeset 562:b9b3473327e3 in lemon for lemon/random.h
 Timestamp:
 02/16/09 19:15:52 (11 years ago)
 Branch:
 default
 Parents:
 561:2eb5c8ca2c91 (diff), 511: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
 Files:

 2 edited
Legend:
 Unmodified
 Added
 Removed

lemon/random.h
r511 r562 3 3 * This file is a part of LEMON, a generic C++ optimization library. 4 4 * 5 * Copyright (C) 2003200 85 * Copyright (C) 20032009 6 6 * Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport 7 7 * (Egervary Research Group on Combinatorial Optimization, EGRES). … … 541 541 /// @{ 542 542 543 ///\name Initialization544 ///545 /// @{546 547 543 /// \brief Default constructor 548 544 /// … … 691 687 } 692 688 693 /// @}694 695 ///\name Uniform distributions696 ///697 /// @{698 699 689 /// \brief Returns a random real number from the range [0, 1) 700 690 /// … … 751 741 return _random_bits::IntConversion<Number, Word>::convert(core); 752 742 } 753 754 /// @}755 743 756 744 unsigned int uinteger() { … … 787 775 ///\name Nonuniform distributions 788 776 /// 789 790 777 ///@{ 791 778 792 /// \brief Returns a random bool 779 /// \brief Returns a random bool with given probability of true result. 793 780 /// 794 781 /// It returns a random bool with given probability of true result. … … 797 784 } 798 785 799 /// Standard Gaussdistribution800 801 /// Standard Gaussdistribution.786 /// Standard normal (Gauss) distribution 787 788 /// Standard normal (Gauss) distribution. 802 789 /// \note The Cartesian form of the BoxMuller 803 790 /// transformation is used to generate a random normal distribution. … … 812 799 return std::sqrt(2*std::log(S)/S)*V1; 813 800 } 814 /// Gaussdistribution with given mean and standard deviation815 816 /// Gaussdistribution 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. 817 804 /// \sa gauss() 818 805 double gauss(double mean,double std_dev) 819 806 { 820 807 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> ¶ms) 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)); 821 848 } 822 849 … … 924 951 ///\name Two dimensional distributions 925 952 /// 926 927 953 ///@{ 928 954 … … 941 967 return dim2::Point<double>(V1,V2); 942 968 } 943 /// A kind of two dimensional Gaussdistribution969 /// A kind of two dimensional normal (Gauss) distribution 944 970 945 971 /// This function provides a turning symmetric twodimensional distribution. 
lemon/random.h
r463 r562 78 78 #include <unistd.h> 79 79 #else 80 #include < windows.h>80 #include <lemon/bits/windows.h> 81 81 #endif 82 82 … … 663 663 seed(getpid() + tv.tv_sec + tv.tv_usec); 664 664 #else 665 FILETIME time; 666 GetSystemTimeAsFileTime(&time); 667 seed(GetCurrentProcessId() + time.dwHighDateTime + time.dwLowDateTime); 665 seed(bits::getWinRndSeed()); 668 666 #endif 669 667 return true;
Note: See TracChangeset
for help on using the changeset viewer.