Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Merge branch 'pikachuyann/simgrid-xbt_random'
authorArnaud Giersch <arnaud.giersch@univ-fcomte.fr>
Thu, 6 Feb 2020 09:57:37 +0000 (10:57 +0100)
committerArnaud Giersch <arnaud.giersch@univ-fcomte.fr>
Thu, 6 Feb 2020 09:57:37 +0000 (10:57 +0100)
include/xbt/random.hpp
src/xbt/random.cpp

index 4c3eff5..4da604f 100644 (file)
@@ -10,14 +10,46 @@ namespace simgrid {
 namespace xbt {
 namespace random {
 
+/**
+ * @brief Tells xbt/random to use the ad-hoc distribution implementation.
+ */
 void set_implem_xbt();
+/**
+ * @brief Tells xbt/random to use the standard library distribution implementation.
+ */
 void set_implem_std();
+/**
+ * @brief Sets the seed of the Mersenne-Twister RNG
+ */
 void set_mersenne_seed(int);
 
-int uniform_int(int, int);
-double uniform_real(double, double);
-double exponential(double);
-double normal(double, double);
+/**
+ * @brief Draws an integer number uniformly between min and max included
+ *
+ * @param min Minimum value
+ * @param max Maximum value
+ */
+int uniform_int(int min, int max);
+/**
+ * @brief Draws a real number uniformly between min and max included
+ *
+ * @param min Minimum value
+ * @param max Maximum value
+ */
+double uniform_real(double min, double max);
+/**
+ * @brief Draws a real number according to the given exponential distribution
+ *
+ * @param lambda Parameter of the exponential law
+ */
+double exponential(double lambda);
+/**
+ * @brief Draws a real number according to the given normal distribution
+ *
+ * @param mean Mean of the normal distribution
+ * @param sd Standard deviation of the normal distribution
+ */
+double normal(double mean, double sd);
 } // namespace random
 } // namespace xbt
 } // namespace simgrid
index 21003c6..79bc21b 100644 (file)
@@ -42,6 +42,9 @@ int uniform_int(int min, int max)
   xbt_assert(
       min <= max,
       "The maximum value for the uniform integer distribution must be greater than or equal to the minimum value");
+  while (value >= mt19937_gen.max() - mt19937_gen.max() % range) {
+    value = mt19937_gen();
+  }
   return value % range + min;
 }