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,
double* first,
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 stddev = &standard_deviation;
@ -389,6 +387,7 @@ namespace Catch {
auto stddev_estimate = Estimate(stddev);
#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);
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_enforce.hpp>
#include <catch2/internal/catch_random_integer_helpers.hpp>
#include <ctime>
#include <random>
@ -21,10 +22,10 @@ namespace Catch {
return static_cast<std::uint32_t>( 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::uint32_t>( std::random_device{}() );
case GenerateFrom::RandomDevice: {
std::random_device rd;
return Detail::fillBitsFrom<std::uint32_t>( rd );
}
default:
CATCH_ERROR("Unknown generation method");