|
11 | 11 | #include <algorithm>
|
12 | 12 | #include <ctype.h>
|
13 | 13 | #include <functional>
|
| 14 | +#include <random> |
14 | 15 | #include <string.h>
|
15 | 16 |
|
16 | 17 | // FUNCTION OBJECTS
|
@@ -294,15 +295,13 @@ void test_copy(char* first, char* last, char* dest) { // test copying template f
|
294 | 295 | CHECK_STR(array2, "aaxx");
|
295 | 296 | }
|
296 | 297 |
|
297 |
| -CSTD size_t frand(CSTD size_t nmax) { // return random value in [0, nmax) |
298 |
| - return CSTD rand() % nmax; |
299 |
| -} |
300 |
| - |
301 | 298 | struct rand_gen { // uniform random number generator
|
| 299 | + STD mt19937 mt; |
| 300 | + |
302 | 301 | typedef CSTD size_t result_type;
|
303 | 302 |
|
304 | 303 | result_type operator()() { // get random value
|
305 |
| - return CSTD rand() & 0xfffff; |
| 304 | + return mt() & 0xfffff; |
306 | 305 | }
|
307 | 306 |
|
308 | 307 | static result_type(min)() { // get minimum value
|
@@ -429,8 +428,13 @@ void test_mutate(char* first, char* last, char* dest) { // test mutating templat
|
429 | 428 | CHECK_STR(array, "ebgf");
|
430 | 429 |
|
431 | 430 | STD random_shuffle(first, last);
|
432 |
| - CSTD size_t (*prand)(CSTD size_t) = &frand; |
433 |
| - STD random_shuffle(first, last, prand); |
| 431 | + |
| 432 | + STD mt19937 mt; |
| 433 | + auto rng_func = [&mt](CSTD size_t nmax) { // return random value in [0, nmax) |
| 434 | + STD uniform_int_distribution<CSTD size_t> dist{0, nmax - 1}; |
| 435 | + return dist(mt); |
| 436 | + }; |
| 437 | + STD random_shuffle(first, last, rng_func); |
434 | 438 |
|
435 | 439 | rand_gen urng;
|
436 | 440 | STD shuffle(first, last, urng);
|
|
0 commit comments