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