Mimic std::uniform_real_distribution.
void set_mersenne_seed(int);
/**
- * @brief Draws an integer number uniformly between min and max included
+ * @brief Draws an integer number uniformly in range [min, max] (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
+ * @brief Draws a real number uniformly in range [min, max) (min included, and max excluded)
*
* @param min Minimum value
* @param max Maximum value
}
// This reuses Boost's uniform real distribution ideas
- constexpr unsigned long divisor = decltype(mt19937_gen)::max() - decltype(mt19937_gen)::min();
+ constexpr unsigned long divisor = decltype(mt19937_gen)::max() - decltype(mt19937_gen)::min() + 1;
unsigned long numerator = mt19937_gen() - decltype(mt19937_gen)::min();
return min + (max - min) * numerator / divisor;
}
SECTION("Using XBT_RNG_xbt")
{
simgrid::xbt::random::set_mersenne_seed(12345);
- REQUIRE_THAT(simgrid::xbt::random::exponential(25), EpsilonApprox(0.00291934351538427348));
+ REQUIRE_THAT(simgrid::xbt::random::exponential(25), EpsilonApprox(0.00291934352469749815));
REQUIRE(simgrid::xbt::random::uniform_int(1, 6) == 4);
- REQUIRE_THAT(simgrid::xbt::random::uniform_real(0, 1), EpsilonApprox(0.31637556043369124970));
- REQUIRE_THAT(simgrid::xbt::random::normal(0, 2), EpsilonApprox(1.62746784745133976635));
+ REQUIRE_THAT(simgrid::xbt::random::uniform_real(0, 1), EpsilonApprox(0.31637556036002933979));
+ REQUIRE_THAT(simgrid::xbt::random::normal(0, 2), EpsilonApprox(1.62746784853777226587));
}
SECTION("Using XBT_RNG_std")