From c94134ec5e8ad6ca98a7b375ef6d5848041b4a48 Mon Sep 17 00:00:00 2001 From: worktycho Date: Sun, 17 May 2015 10:53:16 +0100 Subject: Fix FastRandom seeding Fixes #1815 Fixes #2021 --- src/FastRandom.cpp | 26 +++++++++++++++++++++----- 1 file changed, 21 insertions(+), 5 deletions(-) (limited to 'src/FastRandom.cpp') 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 + #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 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()) { } -- cgit v1.2.3 From adecdc2f07f7c0812eab665d5991f32ce0d6aa63 Mon Sep 17 00:00:00 2001 From: Alexander Harkness Date: Sun, 17 May 2015 16:10:55 +0100 Subject: Fixed typo. --- src/FastRandom.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/FastRandom.cpp') diff --git a/src/FastRandom.cpp b/src/FastRandom.cpp index 639aa65f0..437dc72ff 100644 --- a/src/FastRandom.cpp +++ b/src/FastRandom.cpp @@ -10,7 +10,7 @@ #ifdef _WIN32 #define thread_local static __declspec(thread) -#elseif __OSX__ +#elif __APPLE__ #define thread_local static __thread #endif -- cgit v1.2.3 From 1049d5b706d4e6c29ff9f9960bca3add2c0fd817 Mon Sep 17 00:00:00 2001 From: Alexander Harkness Date: Sun, 17 May 2015 16:30:13 +0100 Subject: properly this time? --- src/FastRandom.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/FastRandom.cpp') diff --git a/src/FastRandom.cpp b/src/FastRandom.cpp index 437dc72ff..c1716f026 100644 --- a/src/FastRandom.cpp +++ b/src/FastRandom.cpp @@ -10,7 +10,7 @@ #ifdef _WIN32 #define thread_local static __declspec(thread) -#elif __APPLE__ +#elif defined __APPLE__ #define thread_local static __thread #endif -- cgit v1.2.3