diff options
author | STRWarrior <niels.breuker@hotmail.nl> | 2015-05-18 09:30:43 +0200 |
---|---|---|
committer | STRWarrior <niels.breuker@hotmail.nl> | 2015-05-18 09:30:43 +0200 |
commit | 007bac638bb732aad7ca63dd3e7a79f5dbb9d2b9 (patch) | |
tree | 8330aefdc4693303f3a944940a919d8bd2333bac /src/FastRandom.cpp | |
parent | Updated the defaults for the overworld world generator (diff) | |
parent | Merge pull request #2049 from mc-server/sapling-probability (diff) | |
download | cuberite-007bac638bb732aad7ca63dd3e7a79f5dbb9d2b9.tar cuberite-007bac638bb732aad7ca63dd3e7a79f5dbb9d2b9.tar.gz cuberite-007bac638bb732aad7ca63dd3e7a79f5dbb9d2b9.tar.bz2 cuberite-007bac638bb732aad7ca63dd3e7a79f5dbb9d2b9.tar.lz cuberite-007bac638bb732aad7ca63dd3e7a79f5dbb9d2b9.tar.xz cuberite-007bac638bb732aad7ca63dd3e7a79f5dbb9d2b9.tar.zst cuberite-007bac638bb732aad7ca63dd3e7a79f5dbb9d2b9.zip |
Diffstat (limited to 'src/FastRandom.cpp')
-rw-r--r-- | src/FastRandom.cpp | 26 |
1 files changed, 21 insertions, 5 deletions
diff --git a/src/FastRandom.cpp b/src/FastRandom.cpp index 737b13535..c1716f026 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) +#elif defined __APPLE__ + #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()) { } |