From 92e1865db4491e79b3420b781c18fd15aa994bdc Mon Sep 17 00:00:00 2001 From: Phillip Stephens Date: Sat, 2 Jul 2016 23:46:18 -0700 Subject: [PATCH] Revert Range(s32,s32) change (causes segfault do to improper results) --- Runtime/CRandom16.hpp | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/Runtime/CRandom16.hpp b/Runtime/CRandom16.hpp index b5d430e2e..a0f3851e3 100644 --- a/Runtime/CRandom16.hpp +++ b/Runtime/CRandom16.hpp @@ -43,8 +43,11 @@ public: inline s32 Range(s32 min, s32 max) { - const s32 rand = Next(); - return min + (rand / ((min - max) + 1)) - rand; + s32 diff = max - min; + s32 rand = -1; + while (rand < 0) + rand = s32((Next() << 16) | Next()); + return rand % diff + min; } static CRandom16* GetRandomNumber() {return g_randomNumber;} @@ -58,7 +61,7 @@ class CGlobalRandom static CGlobalRandom* g_currentGlobalRandom; public: CGlobalRandom(CRandom16& rand) - : m_random(rand), m_prev(g_currentGlobalRandom) + : m_random(rand), m_prev(g_currentGlobalRandom) { g_currentGlobalRandom = this; CRandom16::SetRandomNumber(&m_random);