mirror of
				https://github.com/catchorg/Catch2.git
				synced 2025-11-04 05:59:32 +01:00 
			
		
		
		
	Ensure we always read 32 bit seed from std::random_device
This commit is contained in:
		@@ -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 };
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -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");
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user