From 52b01775c2c94f08786696cae7836ca56f683739 Mon Sep 17 00:00:00 2001 From: jbzdarkid Date: Tue, 19 Nov 2019 09:42:45 -0800 Subject: Fix RNG -- this will break seeds, though. --- Source/Random.cpp | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) (limited to 'Source/Random.cpp') diff --git a/Source/Random.cpp b/Source/Random.cpp index 61fd30f..d9fe678 100644 --- a/Source/Random.cpp +++ b/Source/Random.cpp @@ -1,7 +1,7 @@ #include #include "Random.h" -int Random::s_seed = static_cast(time(nullptr)); // Seed from the time in milliseconds +uint32_t Random::s_seed = static_cast(time(nullptr)); // Seed from the time in milliseconds void Random::SetSeed(int seed) { s_seed = seed; @@ -9,6 +9,7 @@ void Random::SetSeed(int seed) { // Returns a random integer in [min, max] int Random::RandInt(int min, int max) { - s_seed = (214013 * s_seed + 2531011) % 2147483648; - return (s_seed % (max - min + 1)) + min; + s_seed = (214013 * s_seed + 2531011); // Implicit unsigned integer overflow + int32_t maskedSeed = ((s_seed >> 16) & 0x7fff); // Only use bits 16-30 + return (maskedSeed % (max - min + 1)) + min; } -- cgit 1.4.1