Ensure we always read 32 bit seed from std::random_device

This commit is contained in:
Martin Hořeňovský 2023-12-10 21:37:12 +01:00
parent a6f22c5169
commit b7d70ddcd6
No known key found for this signature in database
GPG Key ID: DE48307B8B0D381A
2 changed files with 6 additions and 6 deletions

View File

@ -355,8 +355,6 @@ namespace Catch {
unsigned int n_resamples, unsigned int n_resamples,
double* first, double* first,
double* last) { double* last) {
auto n = static_cast<int>(last - first); // seriously, one can't use integral types without hell in C++
auto mean = &Detail::mean; auto mean = &Detail::mean;
auto stddev = &standard_deviation; auto stddev = &standard_deviation;
@ -389,6 +387,7 @@ namespace Catch {
auto stddev_estimate = Estimate(stddev); auto stddev_estimate = Estimate(stddev);
#endif // CATCH_USE_ASYNC #endif // CATCH_USE_ASYNC
auto n = static_cast<int>(last - first); // seriously, one can't use integral types without hell in C++
double outlier_variance = Detail::outlier_variance(mean_estimate, stddev_estimate, n); double outlier_variance = Detail::outlier_variance(mean_estimate, stddev_estimate, n);
return { mean_estimate, stddev_estimate, outlier_variance }; return { mean_estimate, stddev_estimate, outlier_variance };

View File

@ -9,6 +9,7 @@
#include <catch2/internal/catch_random_seed_generation.hpp> #include <catch2/internal/catch_random_seed_generation.hpp>
#include <catch2/internal/catch_enforce.hpp> #include <catch2/internal/catch_enforce.hpp>
#include <catch2/internal/catch_random_integer_helpers.hpp>
#include <ctime> #include <ctime>
#include <random> #include <random>
@ -21,10 +22,10 @@ namespace Catch {
return static_cast<std::uint32_t>( std::time( nullptr ) ); return static_cast<std::uint32_t>( std::time( nullptr ) );
case GenerateFrom::Default: case GenerateFrom::Default:
case GenerateFrom::RandomDevice: case GenerateFrom::RandomDevice: {
// In theory, a platform could have random_device that returns just std::random_device rd;
// 16 bits. That is still some randomness, so we don't care too much return Detail::fillBitsFrom<std::uint32_t>( rd );
return static_cast<std::uint32_t>( std::random_device{}() ); }
default: default:
CATCH_ERROR("Unknown generation method"); CATCH_ERROR("Unknown generation method");