From b7d70ddcd609a798048f055cf8f5b6803ac06e52 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20Ho=C5=99e=C5=88ovsk=C3=BD?= Date: Sun, 10 Dec 2023 21:37:12 +0100 Subject: [PATCH] Ensure we always read 32 bit seed from std::random_device --- src/catch2/benchmark/detail/catch_stats.cpp | 3 +-- src/catch2/internal/catch_random_seed_generation.cpp | 9 +++++---- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/src/catch2/benchmark/detail/catch_stats.cpp b/src/catch2/benchmark/detail/catch_stats.cpp index a56edfc0..2dd2d864 100644 --- a/src/catch2/benchmark/detail/catch_stats.cpp +++ b/src/catch2/benchmark/detail/catch_stats.cpp @@ -355,8 +355,6 @@ namespace Catch { unsigned int n_resamples, double* first, double* last) { - auto n = static_cast(last - first); // seriously, one can't use integral types without hell in C++ - auto mean = &Detail::mean; auto stddev = &standard_deviation; @@ -389,6 +387,7 @@ namespace Catch { auto stddev_estimate = Estimate(stddev); #endif // CATCH_USE_ASYNC + auto n = static_cast(last - first); // seriously, one can't use integral types without hell in C++ double outlier_variance = Detail::outlier_variance(mean_estimate, stddev_estimate, n); return { mean_estimate, stddev_estimate, outlier_variance }; diff --git a/src/catch2/internal/catch_random_seed_generation.cpp b/src/catch2/internal/catch_random_seed_generation.cpp index 40c468cb..fdc3fa19 100644 --- a/src/catch2/internal/catch_random_seed_generation.cpp +++ b/src/catch2/internal/catch_random_seed_generation.cpp @@ -9,6 +9,7 @@ #include #include +#include #include #include @@ -21,10 +22,10 @@ namespace Catch { return static_cast( std::time( nullptr ) ); case GenerateFrom::Default: - case GenerateFrom::RandomDevice: - // In theory, a platform could have random_device that returns just - // 16 bits. That is still some randomness, so we don't care too much - return static_cast( std::random_device{}() ); + case GenerateFrom::RandomDevice: { + std::random_device rd; + return Detail::fillBitsFrom( rd ); + } default: CATCH_ERROR("Unknown generation method");