summaryrefslogtreecommitdiffstats
path: root/src/FastRandom.cpp
diff options
context:
space:
mode:
authorworktycho <work.tycho@gmail.com>2015-03-15 13:16:37 +0100
committerworktycho <work.tycho@gmail.com>2015-03-15 13:16:37 +0100
commit83531707f3219490eb8ad1e2a7308ff7d4c5fde1 (patch)
treeb379005ad92e48bb696b40fa1b05a35034498710 /src/FastRandom.cpp
parentMerge pull request #1734 from mc-server/pistons (diff)
parentUse thread_local in cFastRandom (diff)
downloadcuberite-83531707f3219490eb8ad1e2a7308ff7d4c5fde1.tar
cuberite-83531707f3219490eb8ad1e2a7308ff7d4c5fde1.tar.gz
cuberite-83531707f3219490eb8ad1e2a7308ff7d4c5fde1.tar.bz2
cuberite-83531707f3219490eb8ad1e2a7308ff7d4c5fde1.tar.lz
cuberite-83531707f3219490eb8ad1e2a7308ff7d4c5fde1.tar.xz
cuberite-83531707f3219490eb8ad1e2a7308ff7d4c5fde1.tar.zst
cuberite-83531707f3219490eb8ad1e2a7308ff7d4c5fde1.zip
Diffstat (limited to 'src/FastRandom.cpp')
-rw-r--r--src/FastRandom.cpp34
1 files changed, 8 insertions, 26 deletions
diff --git a/src/FastRandom.cpp b/src/FastRandom.cpp
index 515dc25ea..737b13535 100644
--- a/src/FastRandom.cpp
+++ b/src/FastRandom.cpp
@@ -6,6 +6,12 @@
#include "Globals.h"
#include "FastRandom.h"
+#ifdef _WIN32
+ #define thread_local __declspec(thread)
+#endif
+
+thread_local unsigned int m_Counter = 0;
+
@@ -86,7 +92,7 @@ public:
cFastRandom::cFastRandom(void) :
- m_LinearRand(static_cast<unsigned>(std::chrono::system_clock::now().time_since_epoch().count()))
+ m_LinearRand(m_Counter++)
{
}
@@ -105,18 +111,6 @@ int cFastRandom::NextInt(int a_Range)
-int cFastRandom::NextInt(int a_Range, int a_Salt)
-{
- m_LinearRand.seed(a_Salt);
- std::uniform_int_distribution<> distribution(0, a_Range - 1);
- return distribution(m_LinearRand);
-}
-
-
-
-
-
-
float cFastRandom::NextFloat(float a_Range)
{
std::uniform_real_distribution<float> distribution(0, a_Range);
@@ -128,18 +122,6 @@ float cFastRandom::NextFloat(float a_Range)
-float cFastRandom::NextFloat(float a_Range, int a_Salt)
-{
- m_LinearRand.seed(a_Salt);
- std::uniform_real_distribution<float> distribution(0, a_Range);
- return distribution(m_LinearRand);
-}
-
-
-
-
-
-
int cFastRandom::GenerateRandomInteger(int a_Begin, int a_End)
{
std::uniform_int_distribution<> distribution(a_Begin, a_End);
@@ -154,7 +136,7 @@ int cFastRandom::GenerateRandomInteger(int a_Begin, int a_End)
// MTRand:
MTRand::MTRand() :
- m_MersenneRand(static_cast<unsigned>(std::chrono::system_clock::now().time_since_epoch().count()))
+ m_MersenneRand(m_Counter++)
{
}