From c3a8a9581321dd37cd2048f510b96ca4787399c2 Mon Sep 17 00:00:00 2001 From: ephphatha Date: Sat, 6 May 2023 13:32:26 +1000 Subject: [PATCH] use stdlib lcg type --- Source/engine/random.cpp | 15 +++++---------- 1 file changed, 5 insertions(+), 10 deletions(-) diff --git a/Source/engine/random.cpp b/Source/engine/random.cpp index bf39dd04d..212340d8a 100644 --- a/Source/engine/random.cpp +++ b/Source/engine/random.cpp @@ -1,6 +1,7 @@ #include "engine/random.hpp" #include +#include #include "utils/stdcompat/abs.hpp" @@ -9,18 +10,12 @@ namespace devilution { /** Current game seed */ uint32_t sglGameSeed; -/** - * Specifies the increment used in the Borland C/C++ pseudo-random number generator algorithm. - */ -const uint32_t RndInc = 1; - -/** - * Specifies the multiplier used in the Borland C/C++ pseudo-random number generator algorithm. - */ -const uint32_t RndMult = 0x015A4E35; +/** Borland C/C++ psuedo-random number generator needed for vanilla compatibility */ +std::linear_congruential_engine diabloGenerator; void SetRndSeed(uint32_t seed) { + diabloGenerator.seed(seed); sglGameSeed = seed; } @@ -39,7 +34,7 @@ void DiscardRandomValues(unsigned count) uint32_t GenerateSeed() { - sglGameSeed = (RndMult * sglGameSeed) + RndInc; + sglGameSeed = diabloGenerator(); return sglGameSeed; }