Index: lemon/random.h
===================================================================
--- lemon/random.h	(revision 487)
+++ lemon/random.h	(revision 515)
@@ -3,5 +3,5 @@
  * 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).
@@ -345,6 +345,16 @@
     };
 
+    template <typename Result, int exp, bool pos = (exp >= 0)>
+    struct ShiftMultiplier {
+      static const Result multiplier() {
+        Result res = ShiftMultiplier<Result, exp / 2>::multiplier();
+        res *= res;
+        if ((exp & 1) == 1) res *= static_cast<Result>(2.0);
+        return res;
+      }
+    };
+
     template <typename Result, int exp>
-    struct ShiftMultiplier {
+    struct ShiftMultiplier<Result, exp, false> {
       static const Result multiplier() {
         Result res = ShiftMultiplier<Result, exp / 2>::multiplier();
@@ -356,5 +366,5 @@
 
     template <typename Result>
-    struct ShiftMultiplier<Result, 0> {
+    struct ShiftMultiplier<Result, 0, true> {
       static const Result multiplier() {
         return static_cast<Result>(1.0);
@@ -363,5 +373,5 @@
 
     template <typename Result>
-    struct ShiftMultiplier<Result, 20> {
+    struct ShiftMultiplier<Result, -20, true> {
       static const Result multiplier() {
         return static_cast<Result>(1.0/1048576.0);
@@ -370,12 +380,12 @@
 
     template <typename Result>
-    struct ShiftMultiplier<Result, 32> {
+    struct ShiftMultiplier<Result, -32, true> {
       static const Result multiplier() {
-        return static_cast<Result>(1.0/4294967296.0);
+        return static_cast<Result>(1.0/424967296.0);
       }
     };
 
     template <typename Result>
-    struct ShiftMultiplier<Result, 53> {
+    struct ShiftMultiplier<Result, -53, true> {
       static const Result multiplier() {
         return static_cast<Result>(1.0/9007199254740992.0);
@@ -384,5 +394,5 @@
 
     template <typename Result>
-    struct ShiftMultiplier<Result, 64> {
+    struct ShiftMultiplier<Result, -64, true> {
       static const Result multiplier() {
         return static_cast<Result>(1.0/18446744073709551616.0);
@@ -404,5 +414,5 @@
 
       static Result convert(RandomCore<Word>& rnd) {
-        return Shifting<Result, shift + rest>::
+        return Shifting<Result, - shift - rest>::
           shift(static_cast<Result>(rnd() >> (bits - rest)));
       }
@@ -414,5 +424,5 @@
 
       static Result convert(RandomCore<Word>& rnd) {
-        return Shifting<Result, shift + bits>::
+        return Shifting<Result, - shift - bits>::
           shift(static_cast<Result>(rnd())) +
           RealConversion<Result, Word, rest-bits, shift + bits>::
@@ -531,8 +541,4 @@
     /// @{
 
-    ///\name Initialization
-    ///
-    /// @{
-
     /// \brief Default constructor
     ///
@@ -681,10 +687,4 @@
     }
 
-    /// @}
-
-    ///\name Uniform distributions
-    ///
-    /// @{
-
     /// \brief Returns a random real number from the range [0, 1)
     ///
@@ -741,6 +741,4 @@
       return _random_bits::IntConversion<Number, Word>::convert(core);
     }
-
-    /// @}
 
     unsigned int uinteger() {
@@ -777,8 +775,7 @@
     ///\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.
@@ -787,7 +784,7 @@
     }
 
-    /// 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.
@@ -802,11 +799,51 @@
       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 <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));
     }
 
@@ -914,5 +951,4 @@
     ///\name Two dimensional distributions
     ///
-
     ///@{
 
@@ -931,5 +967,5 @@
       return dim2::Point<double>(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.
