lemon/random.h
changeset 341 f8832dc16d45
parent 280 e7f8647ce760
child 340 0badf3bb38c2
equal deleted inserted replaced
16:fc290b6cc30f 17:386058cfed26
   838     double gauss(double mean,double std_dev)
   838     double gauss(double mean,double std_dev)
   839     {
   839     {
   840       return gauss()*std_dev+mean;
   840       return gauss()*std_dev+mean;
   841     }
   841     }
   842 
   842 
       
   843     /// Lognormal distribution
       
   844 
       
   845     /// Lognormal distribution. The parameters are the mean and the standard
       
   846     /// deviation of <tt>exp(X)</tt>.
       
   847     ///
       
   848     double lognormal(double n_mean,double n_std_dev)
       
   849     {
       
   850       return std::exp(gauss(n_mean,n_std_dev));
       
   851     }
       
   852     /// Lognormal distribution
       
   853 
       
   854     /// Lognormal distribution. The parameter is an <tt>std::pair</tt> of
       
   855     /// the mean and the standard deviation of <tt>exp(X)</tt>.
       
   856     ///
       
   857     double lognormal(const std::pair<double,double> &params)
       
   858     {
       
   859       return std::exp(gauss(params.first,params.second));
       
   860     }
       
   861     /// Compute the lognormal parameters from mean and standard deviation
       
   862 
       
   863     /// This function computes the lognormal parameters from mean and
       
   864     /// standard deviation. The return value can direcly be passed to
       
   865     /// lognormal().
       
   866     std::pair<double,double> lognormalParamsFromMD(double mean,
       
   867 						   double std_dev)
       
   868     {
       
   869       double fr=std_dev/mean;
       
   870       fr*=fr;
       
   871       double lg=std::log(1+fr);
       
   872       return std::pair<double,double>(std::log(mean)-lg/2.0,std::sqrt(lg));
       
   873     }
       
   874     /// Lognormal distribution with given mean and standard deviation
       
   875     
       
   876     /// Lognormal distribution with given mean and standard deviation.
       
   877     ///
       
   878     double lognormalMD(double mean,double std_dev)
       
   879     {
       
   880       return lognormal(lognormalParamsFromMD(mean,std_dev));
       
   881     }
       
   882     
   843     /// Exponential distribution with given mean
   883     /// Exponential distribution with given mean
   844 
   884 
   845     /// This function generates an exponential distribution random number
   885     /// This function generates an exponential distribution random number
   846     /// with mean <tt>1/lambda</tt>.
   886     /// with mean <tt>1/lambda</tt>.
   847     ///
   887     ///