perf(rng): eliminate per-call random_device overhead

This commit is contained in:
savis
2025-12-26 03:53:35 +01:00
parent ab382cac7c
commit cd6100c3a1

View File

@@ -360,8 +360,7 @@ int number_ex(int from, int to, const char *file, int line)
int returnValue = 0;
std::random_device rd;
XoshiroCpp::Xoshiro128PlusPlus gen(rd());
static thread_local XoshiroCpp::Xoshiro128PlusPlus gen(std::random_device{}());
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)
{
std::random_device rd;
XoshiroCpp::Xoshiro128PlusPlus gen(rd());
static thread_local XoshiroCpp::Xoshiro128PlusPlus gen(std::random_device{}());
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)
{
std::random_device rd;
XoshiroCpp::Xoshiro128PlusPlus gen(rd());
static thread_local XoshiroCpp::Xoshiro128PlusPlus gen(std::random_device{}());
std::normal_distribution<float> distrib(avg, sigma);