From: Yann Duplouy Date: Mon, 21 Oct 2019 09:42:49 +0000 (+0200) Subject: Adding the normal distribution X-Git-Tag: v3.25~386^2~8 X-Git-Url: http://info.iut-bm.univ-fcomte.fr/pub/gitweb/simgrid.git/commitdiff_plain/af116ea50535b17960c8c7d963fe9485787b2651 Adding the normal distribution --- diff --git a/src/xbt/random.cpp b/src/xbt/random.cpp index 7f8af6affb..b0f172a290 100644 --- a/src/xbt/random.cpp +++ b/src/xbt/random.cpp @@ -51,7 +51,12 @@ 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); + double u1 = numeratorA / divisor; + while (u1 < DBL_MIN) { + numeratorA = mt19937_gen() - mt19937_gen.min(); + u1 = numeratorA / divisor; + } + double z0 = sqrt(-2.0 * log(numeratorA / divisor)) * cos(2 * M_PI * numeratorB / divisor); return z0 * sd + mean; }