perf(rng): eliminate per-call random_device overhead
This commit is contained in:
@@ -360,8 +360,7 @@ int number_ex(int from, int to, const char *file, int line)
|
|||||||
|
|
||||||
int returnValue = 0;
|
int returnValue = 0;
|
||||||
|
|
||||||
std::random_device rd;
|
static thread_local XoshiroCpp::Xoshiro128PlusPlus gen(std::random_device{}());
|
||||||
XoshiroCpp::Xoshiro128PlusPlus gen(rd());
|
|
||||||
|
|
||||||
std::uniform_int_distribution<> distrib(from, to);
|
std::uniform_int_distribution<> distrib(from, to);
|
||||||
|
|
||||||
@@ -375,8 +374,7 @@ int number_ex(int from, int to, const char *file, int line)
|
|||||||
|
|
||||||
float fnumber(float from, float to)
|
float fnumber(float from, float to)
|
||||||
{
|
{
|
||||||
std::random_device rd;
|
static thread_local XoshiroCpp::Xoshiro128PlusPlus gen(std::random_device{}());
|
||||||
XoshiroCpp::Xoshiro128PlusPlus gen(rd());
|
|
||||||
|
|
||||||
std::uniform_real_distribution<float> distrib(from, to);
|
std::uniform_real_distribution<float> distrib(from, to);
|
||||||
|
|
||||||
@@ -385,8 +383,7 @@ float fnumber(float from, float to)
|
|||||||
|
|
||||||
float gauss_random(float avg, float sigma)
|
float gauss_random(float avg, float sigma)
|
||||||
{
|
{
|
||||||
std::random_device rd;
|
static thread_local XoshiroCpp::Xoshiro128PlusPlus gen(std::random_device{}());
|
||||||
XoshiroCpp::Xoshiro128PlusPlus gen(rd());
|
|
||||||
|
|
||||||
std::normal_distribution<float> distrib(avg, sigma);
|
std::normal_distribution<float> distrib(avg, sigma);
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user