# HG changeset patch
# User Alpar Juttner <alpar@cs.elte.hu>
# Date 1213893186 -3600
# Node ID 2593e163e407403990ba8f4323f684190a625a62
# Parent  b77fb8c32707cfa7065739d9b82100e3fa8f14af
Lognormal distribution added (#102)

diff -r b77fb8c32707 -r 2593e163e407 lemon/random.h
--- a/lemon/random.h	Thu Oct 23 12:39:39 2008 +0200
+++ b/lemon/random.h	Thu Jun 19 17:33:06 2008 +0100
@@ -840,6 +840,46 @@
       return gauss()*std_dev+mean;
     }
 
+    /// Lognormal distribution
+
+    /// Lognormal distribution. The parameters are the mean and the standard
+    /// deviation of <tt>exp(X)</tt>.
+    ///
+    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 <tt>std::pair</tt> of
+    /// the mean and the standard deviation of <tt>exp(X)</tt>.
+    ///
+    double lognormal(const std::pair<double,double> &params)
+    {
+      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<double,double> lognormalParamsFromMD(double mean,
+						   double std_dev)
+    {
+      double fr=std_dev/mean;
+      fr*=fr;
+      double lg=std::log(1+fr);
+      return std::pair<double,double>(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));
+    }
+    
     /// Exponential distribution with given mean
 
     /// This function generates an exponential distribution random number