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();

View File

@@ -15,7 +15,7 @@
*/
//==============================================================================
#include <ripple/beast/xor_shift_engine.h>
#include <ripple/basics/random.h>
#include <ripple/ledger/BookDirs.h>
#include <ripple/ledger/Directory.h>
#include <ripple/ledger/Sandbox.h>
@@ -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)
{