From b14bdb068a462dd25281ff3a06e2e211c1e23ced Mon Sep 17 00:00:00 2001 From: Scott Schurr Date: Fri, 22 Jun 2018 18:50:02 -0700 Subject: [PATCH] Standardize on default_prng() for non-crypto shuffling --- src/test/basics/PerfLog_test.cpp | 12 +++++------- src/test/ledger/Directory_test.cpp | 10 ++++------ 2 files changed, 9 insertions(+), 13 deletions(-) diff --git a/src/test/basics/PerfLog_test.cpp b/src/test/basics/PerfLog_test.cpp index 7c0bdd6c83..452edeef19 100644 --- a/src/test/basics/PerfLog_test.cpp +++ b/src/test/basics/PerfLog_test.cpp @@ -18,6 +18,7 @@ //============================================================================== #include +#include #include #include #include @@ -48,9 +49,6 @@ class PerfLog_test : public beast::unit_test::suite test::jtx::Env env_ {*this}; beast::Journal j_ {env_.app().journal ("PerfLog_test")}; - // Use this to make calls to random_shuffle() less predictable. - std::default_random_engine shuffler_ {std::random_device{}()}; - // A PerfLog needs a Parent that is a Stoppable and a function to // call if it wants to shutdown the system. This class provides both. struct PerfLogParent : public RootStoppable @@ -370,7 +368,7 @@ public: // Get the all the labels we can use for RPC interfaces without // causing an assert. std::vector labels {ripple::RPC::getHandlerNames()}; - std::shuffle (labels.begin(), labels.end(), shuffler_); + std::shuffle (labels.begin(), labels.end(), default_prng()); // Get two IDs to associate with each label. Errors tend to happen at // boundaries, so we pick IDs starting from zero and ending at @@ -383,7 +381,7 @@ public: std::generate_n (std::back_inserter (ids), labels.size(), [i = std::numeric_limits::max()]() mutable { return i--; }); - std::shuffle (ids.begin(), ids.end(), shuffler_); + std::shuffle (ids.begin(), ids.end(), default_prng()); // Start all of the RPC commands twice to show they can all be tracked // simultaneously. @@ -591,7 +589,7 @@ public: jobs.emplace_back (job.first, job.second.name()); } } - std::shuffle (jobs.begin(), jobs.end(), shuffler_); + std::shuffle (jobs.begin(), jobs.end(), default_prng()); // Walk through all of the jobs, enqueuing every job once. Check // the jobs data with every addition. @@ -926,7 +924,7 @@ public: std::uniform_int_distribution<> dis(0, jobTypes.size() - 1); auto iter {jobTypes.begin()}; - std::advance (iter, dis (shuffler_)); + std::advance (iter, dis (default_prng())); jobType = iter->second.type(); jobTypeName = iter->second.name(); diff --git a/src/test/ledger/Directory_test.cpp b/src/test/ledger/Directory_test.cpp index c1287b1be8..6c5fb76123 100644 --- a/src/test/ledger/Directory_test.cpp +++ b/src/test/ledger/Directory_test.cpp @@ -15,7 +15,7 @@ */ //============================================================================== -#include +#include #include #include #include @@ -184,8 +184,6 @@ struct Directory_test : public beast::unit_test::suite auto const charlie = Account ("charlie"); auto const gw = Account ("gw"); - beast::xor_shift_engine eng; - Env env(*this); env.fund(XRP(1000000), alice, charlie, gw); @@ -228,7 +226,7 @@ struct Directory_test : public beast::unit_test::suite BEAST_EXPECT(! dirIsEmpty (*env.closed(), keylet::ownerDir(alice))); - std::shuffle (cl.begin(), cl.end(), eng); + std::shuffle (cl.begin(), cl.end(), default_prng()); for (auto const& c : cl) { @@ -261,7 +259,7 @@ struct Directory_test : public beast::unit_test::suite // Now fill the offers in a random order. Offer // entries will drop, and be replaced by trust // lines that are implicitly created. - std::shuffle (cl.begin(), cl.end(), eng); + std::shuffle (cl.begin(), cl.end(), default_prng()); for (auto const& c : cl) { @@ -272,7 +270,7 @@ struct Directory_test : public beast::unit_test::suite // Finally, Alice now sends the funds back to // Charlie. The implicitly created trust lines // should drop away: - std::shuffle (cl.begin(), cl.end(), eng); + std::shuffle (cl.begin(), cl.end(), default_prng()); for (auto const& c : cl) {