aboutsummaryrefslogtreecommitdiff
path: root/src/common/Utilities/Random.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/common/Utilities/Random.cpp')
-rw-r--r--src/common/Utilities/Random.cpp17
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;
-}