diff options
author | Shauren <shauren.trinity@gmail.com> | 2025-07-09 12:20:10 +0200 |
---|---|---|
committer | Shauren <shauren.trinity@gmail.com> | 2025-07-09 12:20:10 +0200 |
commit | 2c74626e66e5fd88683348f37f4b30ab397bf55b (patch) | |
tree | 50b4dee8256022d29c0146834ab604d16c5d9ddd /src/common/Utilities/Random.cpp | |
parent | c7f5696479bb85c8fc7ee0d9fdaeb92e2b32213f (diff) |
Core/Random: Use standard aligned operator new and remove RandomEngine singleton instance (it is trivially constructible)
Diffstat (limited to 'src/common/Utilities/Random.cpp')
-rw-r--r-- | src/common/Utilities/Random.cpp | 17 |
1 files changed, 6 insertions, 11 deletions
diff --git a/src/common/Utilities/Random.cpp b/src/common/Utilities/Random.cpp index 973832a1cf3..1cf4da95bfe 100644 --- a/src/common/Utilities/Random.cpp +++ b/src/common/Utilities/Random.cpp @@ -21,16 +21,16 @@ #include <memory> #include <random> -static thread_local std::unique_ptr<SFMTRand> sfmtRand; -static RandomEngine engine; - -static SFMTRand* GetRng() +namespace { - if (!sfmtRand) - sfmtRand = std::make_unique<SFMTRand>(); +constexpr RandomEngine engine; +SFMTRand* GetRng() noexcept +{ + thread_local std::unique_ptr<SFMTRand> sfmtRand = std::make_unique<SFMTRand>(); return sfmtRand.get(); } +} int32 irand(int32 min, int32 max) { @@ -89,8 +89,3 @@ uint32 urandweighted(size_t count, double const* chances) std::discrete_distribution<uint32> dd(chances, chances + count); return dd(engine); } - -RandomEngine& RandomEngine::Instance() -{ - return engine; -} |