#include "xbt/random.hpp"
#include "xbt/asserts.h"
+#include <limits>
#include <random>
namespace simgrid {
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 < std::numeric_limits<double>::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;
}