From b88c61c16de5d3f8f7c0ef6a8d7eb10e3b5d26ea Mon Sep 17 00:00:00 2001 From: Jamie Reece Wilson Date: Fri, 17 Nov 2023 08:19:26 +0000 Subject: [PATCH] [*] Amend 999f3e69 --- Source/RNG/AuRandomDevice.cpp | 4 ++-- Source/RNG/AuWELL.cpp | 6 +++--- Source/RNG/AuWELL.hpp | 14 +++++++++++--- 3 files changed, 16 insertions(+), 8 deletions(-) diff --git a/Source/RNG/AuRandomDevice.cpp b/Source/RNG/AuRandomDevice.cpp index dec52c12..64ecfa33 100644 --- a/Source/RNG/AuRandomDevice.cpp +++ b/Source/RNG/AuRandomDevice.cpp @@ -172,7 +172,7 @@ namespace Aurora::RNG auto uMassiveWord = NextU32(); auto uUpperBound = AuPageRoundUp(uRange, 2); AuUInt32 uNext {}; - while ((uNext = (uMassiveWord & (uUpperBound - 1))) >= uRange) + while ((uNext = (uMassiveWord & (uUpperBound - 1))) > uRange) { uMassiveWord = NextU32(); } @@ -190,7 +190,7 @@ namespace Aurora::RNG auto uMassiveWord = NextU32(); auto uUpperBound = AuPageRoundUp(uRange, 2); AuUInt32 uNext {}; - while ((uNext = (uMassiveWord & (uUpperBound - 1))) >= uRange) + while ((uNext = (uMassiveWord & (uUpperBound - 1))) > uRange) { uMassiveWord = NextU32(); } diff --git a/Source/RNG/AuWELL.cpp b/Source/RNG/AuWELL.cpp index e6824d0c..09866a90 100644 --- a/Source/RNG/AuWELL.cpp +++ b/Source/RNG/AuWELL.cpp @@ -49,21 +49,21 @@ static auline void WELL_SeedRand(WELLRand *rand, AuUInt32 seed) /** * Creates a new random number generator from a given seed. */ -WELLRand &&WELL_SeedRand(AuUInt32 seed) +WELLRand WELL_SeedRand(AuUInt32 seed) { WELLRand rand {}; WELL_SeedRand(&rand, seed); return AuMove(rand); } -WELLRand &&WELL_SeedRand64(AuUInt64 seed) +WELLRand WELL_SeedRand64(AuUInt64 seed) { WELLRand rand {}; WELL_SeedRand64(&rand, seed); return AuMove(rand); } -WELLRand &&WELL_SeedRandBig64(const AuArray &seed) +WELLRand WELL_SeedRandBig64(const AuArray &seed) { WELLRand rand {}; static_assert(64 == sizeof(rand.state)); diff --git a/Source/RNG/AuWELL.hpp b/Source/RNG/AuWELL.hpp index e2698a9e..c9ea5d34 100644 --- a/Source/RNG/AuWELL.hpp +++ b/Source/RNG/AuWELL.hpp @@ -6,6 +6,14 @@ struct WELLRand int index {}; AuFutexMutex lock; + inline WELLRand() = default; + + inline WELLRand(WELLRand &&rand) + { + AuMemcpy(this->state, rand.state, sizeof(this->state)); + this->index = rand.index; + } + inline WELLRand &operator =(WELLRand &&rand) { AuMemcpy(this->state, rand.state, sizeof(this->state)); @@ -14,8 +22,8 @@ struct WELLRand } }; -WELLRand &&WELL_SeedRand(AuUInt32 seed); -WELLRand &&WELL_SeedRandBig64(const AuArray &seed); -WELLRand &&WELL_SeedRand64(AuUInt64 seed); +WELLRand WELL_SeedRand(AuUInt32 seed); +WELLRand WELL_SeedRandBig64(const AuArray &seed); +WELLRand WELL_SeedRand64(AuUInt64 seed); AuUInt32 WELL_NextLong(WELLRand* rand); void WELL_NextBytes(WELLRand *rand, void *in, AuUInt32 length); \ No newline at end of file