From: Yann Duplouy Date: Mon, 21 Oct 2019 09:41:50 +0000 (+0200) Subject: Adding the normal distribution X-Git-Tag: v3.25~386^2~9 X-Git-Url: http://info.iut-bm.univ-fcomte.fr/pub/gitweb/simgrid.git/commitdiff_plain/65e50c050d9856bf4728824596bf75d9b3b0ab6e Adding the normal distribution --- diff --git a/include/xbt/random.hpp b/include/xbt/random.hpp index 84e8182a36..cf2b168c18 100644 --- a/include/xbt/random.hpp +++ b/include/xbt/random.hpp @@ -14,6 +14,7 @@ namespace random { int uniform_int(int, int); double uniform_real(double, double); double exponential(double); +double normal(double, double); } // namespace random } // namespace xbt } // namespace simgrid diff --git a/src/xbt/random.cpp b/src/xbt/random.cpp index 95aed12a15..7f8af6affb 100644 --- a/src/xbt/random.cpp +++ b/src/xbt/random.cpp @@ -46,6 +46,15 @@ double exponential(double lambda) return -1 / lambda * log(numerator / divisor); } +double normal(double mean, double sd) +{ + unsigned long numeratorA = mt19937_gen() - mt19937_gen.min(); + unsigned long numeratorB = mt19937_gen() - mt19937_gen.min(); + unsigned long divisor = mt19937_gen.max() - mt19937_gen.min(); + double z0 = sqrt(-2.0 * log(numeratorA / divisor)) * cos(2 * M_PI * numeratorB / divisor); + return z0 * sd + mean; +} + } // namespace random } // namespace xbt } // namespace simgrid