diff options
author | MarcoFalke <falke.marco@gmail.com> | 2022-04-08 12:56:25 +0200 |
---|---|---|
committer | MacroFake <falke.marco@gmail.com> | 2022-05-08 11:47:55 +0200 |
commit | fa4fb8d98b7e8e5ea2db35bf239fa7f248da5d8e (patch) | |
tree | 4d61028adf2afa3f80429b3bd2386ceac524de48 /src/test/random_tests.cpp | |
parent | faa5c62967174f1dd66e8a4ba61ab29c867cf450 (diff) |
random: Add FastRandomContext::rand_uniform_delay
Diffstat (limited to 'src/test/random_tests.cpp')
-rw-r--r-- | src/test/random_tests.cpp | 10 |
1 files changed, 10 insertions, 0 deletions
diff --git a/src/test/random_tests.cpp b/src/test/random_tests.cpp index 978a7bee4d..a3daefa599 100644 --- a/src/test/random_tests.cpp +++ b/src/test/random_tests.cpp @@ -31,6 +31,16 @@ BOOST_AUTO_TEST_CASE(fastrandom_tests) BOOST_CHECK_EQUAL(GetRandMicros(std::chrono::hours{1}).count(), 2917185654); BOOST_CHECK_EQUAL(GetRandMillis(std::chrono::hours{1}).count(), 2144374); } + { + constexpr SteadySeconds time_point{1s}; + FastRandomContext ctx{true}; + BOOST_CHECK_EQUAL(7, ctx.rand_uniform_delay(time_point, 9s).time_since_epoch().count()); + BOOST_CHECK_EQUAL(-6, ctx.rand_uniform_delay(time_point, -9s).time_since_epoch().count()); + BOOST_CHECK_EQUAL(1, ctx.rand_uniform_delay(time_point, 0s).time_since_epoch().count()); + BOOST_CHECK_EQUAL(1467825113502396065, ctx.rand_uniform_delay(time_point, 9223372036854775807s).time_since_epoch().count()); + BOOST_CHECK_EQUAL(-970181367944767837, ctx.rand_uniform_delay(time_point, -9223372036854775807s).time_since_epoch().count()); + BOOST_CHECK_EQUAL(24761, ctx.rand_uniform_delay(time_point, 9h).time_since_epoch().count()); + } BOOST_CHECK_EQUAL(ctx1.rand32(), ctx2.rand32()); BOOST_CHECK_EQUAL(ctx1.rand32(), ctx2.rand32()); BOOST_CHECK_EQUAL(ctx1.rand64(), ctx2.rand64()); |