summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorworktycho <work.tycho@gmail.com>2015-05-17 11:53:16 +0200
committertycho <work.tycho@gmail.com>2015-05-17 14:16:18 +0200
commitc94134ec5e8ad6ca98a7b375ef6d5848041b4a48 (patch)
tree6214c1cb269e334f79a9714a19b151fa8a36db21 /src
parentShould disable coveralls. (diff)
downloadcuberite-c94134ec5e8ad6ca98a7b375ef6d5848041b4a48.tar
cuberite-c94134ec5e8ad6ca98a7b375ef6d5848041b4a48.tar.gz
cuberite-c94134ec5e8ad6ca98a7b375ef6d5848041b4a48.tar.bz2
cuberite-c94134ec5e8ad6ca98a7b375ef6d5848041b4a48.tar.lz
cuberite-c94134ec5e8ad6ca98a7b375ef6d5848041b4a48.tar.xz
cuberite-c94134ec5e8ad6ca98a7b375ef6d5848041b4a48.tar.zst
cuberite-c94134ec5e8ad6ca98a7b375ef6d5848041b4a48.zip
Diffstat (limited to '')
-rw-r--r--src/FastRandom.cpp26
1 files changed, 21 insertions, 5 deletions
diff --git a/src/FastRandom.cpp b/src/FastRandom.cpp
index 737b13535..639aa65f0 100644
--- a/src/FastRandom.cpp
+++ b/src/FastRandom.cpp
@@ -6,12 +6,28 @@
#include "Globals.h"
#include "FastRandom.h"
+#include <random>
+
#ifdef _WIN32
- #define thread_local __declspec(thread)
+ #define thread_local static __declspec(thread)
+#elseif __OSX__
+ #define thread_local static __thread
#endif
-thread_local unsigned int m_Counter = 0;
-
+static unsigned int GetRandomSeed()
+{
+ thread_local bool SeedCounterInitialized = 0;
+ thread_local unsigned int SeedCounter = 0;
+
+ if (!SeedCounterInitialized)
+ {
+ std::random_device rd;
+ std::uniform_int_distribution<unsigned int> dist;
+ SeedCounter = dist(rd);
+ SeedCounterInitialized = true;
+ }
+ return ++SeedCounter;
+}
@@ -92,7 +108,7 @@ public:
cFastRandom::cFastRandom(void) :
- m_LinearRand(m_Counter++)
+ m_LinearRand(GetRandomSeed())
{
}
@@ -136,7 +152,7 @@ int cFastRandom::GenerateRandomInteger(int a_Begin, int a_End)
// MTRand:
MTRand::MTRand() :
- m_MersenneRand(m_Counter++)
+ m_MersenneRand(GetRandomSeed())
{
}