Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Adding the exponential distribution
authorYann Duplouy <yann.duplouy@inria.fr>
Mon, 21 Oct 2019 09:37:41 +0000 (11:37 +0200)
committerYann Duplouy <yann.duplouy@inria.fr>
Mon, 21 Oct 2019 09:37:41 +0000 (11:37 +0200)
include/xbt/random.hpp
src/xbt/random.cpp

index 7326447..84e8182 100644 (file)
@@ -13,6 +13,7 @@ namespace xbt {
 namespace random {
 int uniform_int(int, int);
 double uniform_real(double, double);
+double exponential(double);
 } // namespace random
 } // namespace xbt
 } // namespace simgrid
index 95d4922..95aed12 100644 (file)
@@ -39,6 +39,13 @@ double uniform_real(double min, double max)
   return min + (max - min) * numerator / divisor;
 }
 
+double exponential(double lambda)
+{
+  unsigned long numerator = mt19937_gen() - mt19937_gen.min();
+  unsigned long divisor   = mt19937_gen.max() - mt19937_gen.min();
+  return -1 / lambda * log(numerator / divisor);
+}
+
 } // namespace random
 } // namespace xbt
 } // namespace simgrid