From 5243882ed56b0b9cb75909ab65291f0ff72376f1 Mon Sep 17 00:00:00 2001 From: Faerbit Date: Sat, 13 Jun 2020 21:30:03 +0200 Subject: [PATCH] Make random generator thread_local. --- util.h | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/util.h b/util.h index c26f25d..ae9d1a0 100644 --- a/util.h +++ b/util.h @@ -4,6 +4,7 @@ #include #include #include +#include const double infinity = std::numeric_limits::infinity(); const double pi = 3.1415926535897932385; @@ -15,8 +16,9 @@ inline double degrees_to_radians(double degrees) { inline double random_double() { static std::uniform_real_distribution distribution(0.0, 1.0); //static std::mt19937 generator(std::time(nullptr)); - static std::mt19937 generator(std::random_device{}()); - return distribution(generator); + static thread_local std::mt19937 generator(std::random_device{}()); + static std::function rand_gen = std::bind(distribution, generator); + return rand_gen(); } inline double random_double(double min, double max) {