@@ -71,7 +71,7 @@ TEST_CASE("Test Random", "[math]")
71
71
REQUIRE (b2_result < 50 );
72
72
73
73
emp::RandomStdAdaptor randomStd (rnd);
74
- REQUIRE (randomStd (4 ) == 1 );
74
+ REQUIRE (randomStd (4 ) == 3 );
75
75
76
76
REQUIRE (rnd.GetRandGeometric (1 ) == 1 );
77
77
REQUIRE (rnd.GetRandGeometric (0 ) == std::numeric_limits<uint32_t >::infinity ());
@@ -295,3 +295,48 @@ TEST_CASE("Another Test random", "[math]")
295
295
REQUIRE (v.first + v.second == 0 );
296
296
}
297
297
}
298
+
299
+ TEST_CASE (" Calling ResetSeed should reset all generator internal state" , " [math]" ) {
300
+
301
+ SECTION (" Test internal 'value'" ) {
302
+ // Get Seed
303
+ emp::Random rnd (-1 ); // Initialize without a seed
304
+ rnd.ResetSeed (5 );
305
+ REQUIRE (rnd.GetSeed () == 5 );
306
+
307
+ emp::vector<int > sequence_a;
308
+ for (size_t i = 0 ; i < 10 ; ++i) {
309
+ sequence_a.emplace_back (rnd.GetInt (10000 ));
310
+ }
311
+
312
+ rnd.ResetSeed (5 );
313
+ emp::vector<int > sequence_b;
314
+ for (size_t i = 0 ; i < 10 ; ++i) {
315
+ sequence_b.emplace_back (rnd.GetInt (10000 ));
316
+ }
317
+
318
+ // Tests internal 'value'
319
+ REQUIRE (sequence_a == sequence_b);
320
+ }
321
+
322
+ SECTION (" Test internal expV" ) {
323
+ emp::Random rnd (10 );
324
+ rnd.GetRandNormal (); // Adjusts expV with time-based seed generator
325
+
326
+ rnd.ResetSeed (4 ); // Should reset expV
327
+ emp::vector<double > norm_seq_a;
328
+ for (size_t i = 0 ; i < 1000 ; ++i) {
329
+ norm_seq_a.emplace_back (rnd.GetRandNormal ());
330
+ }
331
+
332
+ rnd.ResetSeed (4 );
333
+ emp::vector<double > norm_seq_b;
334
+ for (size_t i = 0 ; i < 1000 ; ++i) {
335
+ norm_seq_b.emplace_back (rnd.GetRandNormal ());
336
+ }
337
+
338
+ // Tests internal expV
339
+ REQUIRE (norm_seq_a == norm_seq_b);
340
+ }
341
+
342
+ }
0 commit comments