From 2c74626e66e5fd88683348f37f4b30ab397bf55b Mon Sep 17 00:00:00 2001 From: Shauren Date: Wed, 9 Jul 2025 12:20:10 +0200 Subject: Core/Random: Use standard aligned operator new and remove RandomEngine singleton instance (it is trivially constructible) --- src/common/Utilities/Random.cpp | 17 ++++++----------- 1 file changed, 6 insertions(+), 11 deletions(-) (limited to 'src/common/Utilities/Random.cpp') 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 #include -static thread_local std::unique_ptr sfmtRand; -static RandomEngine engine; - -static SFMTRand* GetRng() +namespace { - if (!sfmtRand) - sfmtRand = std::make_unique(); +constexpr RandomEngine engine; +SFMTRand* GetRng() noexcept +{ + thread_local std::unique_ptr sfmtRand = std::make_unique(); return sfmtRand.get(); } +} int32 irand(int32 min, int32 max) { @@ -89,8 +89,3 @@ uint32 urandweighted(size_t count, double const* chances) std::discrete_distribution dd(chances, chances + count); return dd(engine); } - -RandomEngine& RandomEngine::Instance() -{ - return engine; -} -- cgit v1.2.3