From 986e61cf54aac826ac52e91245ffdc16d96016e2 Mon Sep 17 00:00:00 2001 From: "Scott E. Graves" Date: Sat, 31 Aug 2024 19:34:24 -0500 Subject: [PATCH] updated build system --- support/include/utils/common.hpp | 5 +++-- support/src/utils/common.cpp | 2 +- support/test/src/test.cpp | 4 +++- 3 files changed, 7 insertions(+), 4 deletions(-) diff --git a/support/include/utils/common.hpp b/support/include/utils/common.hpp index f413a3d8..a7937906 100644 --- a/support/include/utils/common.hpp +++ b/support/include/utils/common.hpp @@ -114,8 +114,9 @@ inline auto generate_random_between(data_t begin, data_t end) -> data_t { throw std::range_error("end must be greater than begin"); } - std::random_device rd{}; - std::mt19937 gen(static_cast(std::time(nullptr) ^ rd())); + thread_local std::random_device rd{}; + thread_local std::mt19937 gen( + static_cast(std::time(nullptr) ^ rd())); std::uniform_int_distribution dis(begin, end); return dis(gen); } diff --git a/support/src/utils/common.cpp b/support/src/utils/common.cpp index a919a83c..57f309f1 100644 --- a/support/src/utils/common.cpp +++ b/support/src/utils/common.cpp @@ -67,7 +67,7 @@ auto compare_version_strings(std::wstring_view version1, #if defined(PROJECT_ENABLE_STDUUID) auto create_uuid_string() -> std::string { - std::random_device random_device; + std::random_device random_device{}; auto seed_data = std::array{}; std::generate(std::begin(seed_data), std::end(seed_data), std::ref(random_device)); diff --git a/support/test/src/test.cpp b/support/test/src/test.cpp index 87fad0bf..c93d76fb 100644 --- a/support/test/src/test.cpp +++ b/support/test/src/test.cpp @@ -64,7 +64,9 @@ auto create_random_file(std::size_t size) -> utils::file::i_file & { #if defined(PROJECT_ENABLE_LIBSODIUM) randombytes_buf(buf.data(), buf.size()); #else // !defined(PROJECT_ENABLE_LIBSODIUM) - std::mt19937 gen(std::random_device{}()); + thread_local std::random_device rd{}; + thread_local std::mt19937 gen( + static_cast(std::time(nullptr) ^ rd())); std::uniform_int_distribution dis(0U, 255U); std::generate(buf.begin(), buf.end(), [&]() -> auto { return dis(gen); }); #endif // defined(PROJECT_ENABLE_LIBSODIUM)