1
0
cuberite-2a/src/FastRandom.cpp
peterbell10 84289a2ba9
Cleanup some workarounds and warnings (#4735)
* Cleanup thread_local usage in FastRandom

* Use constexpr to avoid clang warning

* Fix more Wglobal-constructor warnings

* Make MSVC happy?
2020-05-10 16:16:49 +00:00

36 lines
426 B
C++

// FastRandom.cpp
#include "Globals.h"
#include "FastRandom.h"
MTRand & GetRandomProvider()
{
thread_local MTRand Random = []
{
cRandomDeviceSeeder Seeder;
return MTRand(Seeder);
}();
return Random;
}
UInt32 Detail::GetRandomSeed()
{
thread_local UInt32 SeedCounter = []
{
std::random_device rd;
std::uniform_int_distribution<UInt32> dist;
return dist(rd);
}();
return ++SeedCounter;
}