Standardize on default_prng() for non-crypto shuffling

This commit is contained in:
Scott Schurr
2018-06-22 18:50:02 -07:00
committed by Nik Bougalis
parent 8098cba4c2
commit b14bdb068a
2 changed files with 9 additions and 13 deletions

View File

@@ -18,6 +18,7 @@
//==============================================================================
#include <ripple/basics/PerfLog.h>
#include <ripple/basics/random.h>
#include <ripple/beast/unit_test.h>
#include <ripple/json/json_reader.h>
#include <ripple/protocol/JsonFields.h>
@@ -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<char const*> 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<std::uint64_t>::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();