Added
Link Here
|
1 |
commit 81dfbed7428a526acf7c97937902fc36d7eaeb21 |
2 |
Author: Kevin Ushey <kevinushey@gmail.com> |
3 |
Date: Wed Sep 21 15:50:44 2022 -0700 |
4 |
|
5 |
Use compatible RNG with shuffle (#1688) |
6 |
|
7 |
Fixes #1687 |
8 |
|
9 |
diff --git src/testthat/vendor/catch.h src/testthat/vendor/catch.h |
10 |
index e8a10b07..83818641 100644 |
11 |
--- src/testthat/vendor/catch.h |
12 |
+++ src/testthat/vendor/catch.h |
13 |
@@ -7165,27 +7165,23 @@ namespace Catch { |
14 |
// #included from: catch_test_case_registry_impl.hpp |
15 |
#define TWOBLUECUBES_CATCH_TEST_CASE_REGISTRY_IMPL_HPP_INCLUDED |
16 |
|
17 |
-#include <vector> |
18 |
+#include <algorithm> |
19 |
#include <set> |
20 |
#include <sstream> |
21 |
-#include <algorithm> |
22 |
+#include <vector> |
23 |
+ |
24 |
+#ifdef CATCH_CONFIG_CPP11_SHUFFLE |
25 |
+#include <random> |
26 |
+#endif |
27 |
|
28 |
namespace Catch { |
29 |
|
30 |
struct RandomNumberGenerator { |
31 |
- typedef std::ptrdiff_t result_type; |
32 |
- |
33 |
- result_type operator()( result_type n ) const { return rand() % n; } |
34 |
- |
35 |
-#ifdef CATCH_CONFIG_CPP11_SHUFFLE |
36 |
- static constexpr result_type min() { return 0; } |
37 |
- static constexpr result_type max() { return 1000000; } |
38 |
- result_type operator()() const { return rand() % max(); } |
39 |
-#endif |
40 |
template<typename V> |
41 |
static void shuffle( V& vector ) { |
42 |
- RandomNumberGenerator rng; |
43 |
#ifdef CATCH_CONFIG_CPP11_SHUFFLE |
44 |
+ std::random_device device; |
45 |
+ std::mt19937 rng( device() ); |
46 |
std::shuffle( vector.begin(), vector.end(), rng ); |
47 |
#else |
48 |
random_shuffle( vector.begin(), vector.end(), rng ); |