diff --git a/src/random.cpp b/src/random.cpp --- a/src/random.cpp +++ b/src/random.cpp @@ -403,6 +403,9 @@ } std::vector FastRandomContext::randbytes(size_t len) { + if (requires_seed) { + RandomSeed(); + } std::vector ret(len); if (len > 0) { rng.Output(&ret[0], len); diff --git a/src/test/random_tests.cpp b/src/test/random_tests.cpp --- a/src/test/random_tests.cpp +++ b/src/test/random_tests.cpp @@ -36,12 +36,19 @@ BOOST_CHECK(ctx1.randbytes(50) == ctx2.randbytes(50)); // Check that a nondeterministic ones are not - FastRandomContext ctx3; - FastRandomContext ctx4; - // extremely unlikely to be equal - BOOST_CHECK(ctx3.rand64() != ctx4.rand64()); - BOOST_CHECK(ctx3.rand256() != ctx4.rand256()); - BOOST_CHECK(ctx3.randbytes(7) != ctx4.randbytes(7)); + { + FastRandomContext ctx3, ctx4; + // extremely unlikely to be equal + BOOST_CHECK(ctx3.rand64() != ctx4.rand64()); + } + { + FastRandomContext ctx3, ctx4; + BOOST_CHECK(ctx3.rand256() != ctx4.rand256()); + } + { + FastRandomContext ctx3, ctx4; + BOOST_CHECK(ctx3.randbytes(7) != ctx4.randbytes(7)); + } } BOOST_AUTO_TEST_CASE(fastrandom_randbits) {