From ecacb6cdc650b6964fc7f7b61bf33728409cc13c Mon Sep 17 00:00:00 2001 From: Merry Date: Tue, 19 Jul 2022 20:47:26 +0100 Subject: [PATCH] tests/rand_int: Expose PRNG --- tests/rand_int.h | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/tests/rand_int.h b/tests/rand_int.h index 9b4dddb8..3997a431 100644 --- a/tests/rand_int.h +++ b/tests/rand_int.h @@ -8,14 +8,20 @@ #include #include +namespace detail { +inline std::mt19937 g_rand_int_generator = [] { + std::random_device rd; + std::mt19937 mt{rd()}; + return mt; +}(); +} // namespace detail + template T RandInt(T min, T max) { static_assert(std::is_integral_v, "T must be an integral type."); static_assert(!std::is_same_v && !std::is_same_v, "Using char with uniform_int_distribution is undefined behavior."); - static std::random_device rd; - static std::mt19937 mt(rd()); std::uniform_int_distribution rand(min, max); - return rand(mt); + return rand(detail::g_rand_int_generator); }