From 026d5e71fae1f88baff3d941b8951b2da90ebdc9 Mon Sep 17 00:00:00 2001 From: "Michael Cook (mackal)" Date: Sun, 14 Dec 2014 19:38:23 -0500 Subject: [PATCH] Adjust common/random.h based on N3551 --- common/random.h | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/common/random.h b/common/random.h index ef2b3ef73..514c483e1 100644 --- a/common/random.h +++ b/common/random.h @@ -33,31 +33,31 @@ namespace EQEmu { class Random { public: // AKA old MakeRandomInt - const int Int(int low, int high) + int Int(int low, int high) { if (low > high) std::swap(low, high); - return std::uniform_int_distribution(low, high)(m_gen); // [low, high] + return int_dist(m_gen, int_param_t(low, high)); // [low, high] } // AKA old MakeRandomFloat - const double Real(double low, double high) + double Real(double low, double high) { if (low > high) std::swap(low, high); - return std::uniform_real_distribution(low, high)(m_gen); // [low, high) + return real_dist(m_gen, real_param_t(low, high)); // [low, high) } // example Roll(50) would have a 50% success rate // Roll(100) 100%, etc // valid values 0-100 (well, higher works too but ...) - const bool Roll(const int required) + bool Roll(const int required) { return Int(0, 99) < required; } // valid values 0.0 - 1.0 - const bool Roll(const double required) + bool Roll(const double required) { return Real(0.0, 1.0) <= required; } @@ -76,7 +76,11 @@ namespace EQEmu { } private: + typedef std::uniform_int_distribution::param_type int_param_t; + typedef std::uniform_real_distribution::param_type real_param_t; std::mt19937 m_gen; + std::uniform_int_distribution int_dist; + std::uniform_real_distribution real_dist; }; }