From a8f7447cf43184160ade0de01199462c11f3c109 Mon Sep 17 00:00:00 2001 From: Boris Kolpackov Date: Tue, 16 May 2023 06:32:16 +0200 Subject: Randomize URL query order within each priority --- bbot/agent/agent.cxx | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/bbot/agent/agent.cxx b/bbot/agent/agent.cxx index ad8cd74..6163c14 100644 --- a/bbot/agent/agent.cxx +++ b/bbot/agent/agent.cxx @@ -26,6 +26,7 @@ #include // thread::hardware_concurrency() #include #include // setw() +#include // iota() #include #include // generic_category() @@ -53,6 +54,8 @@ using namespace bbot; using std::cout; using std::endl; +static std::mt19937 rand_gen (std::random_device {} ()); + // According to the standard, atomic's use in the signal handler is only safe // if it's lock-free. // @@ -1968,9 +1971,9 @@ try // // NOTE: consider updating agent_checksum if making any logic changes. // - auto rand_sleep = [g = std::mt19937 (std::random_device {} ())] () mutable + auto rand_sleep = [] () { - return std::uniform_int_distribution (50, 60) (g); + return std::uniform_int_distribution (50, 60) (rand_gen); }; optional imode; @@ -2190,10 +2193,14 @@ try // Note that we have to do it while holding the lock on all the machines // since we don't know which machine we will need. // - // @@ TODO: need to iterate in random order somehow. - // - for (const string& u: urls) + vector rurls (urls.size ()); + std::iota (rurls.begin (), rurls.end (), urls.begin ()); + std::shuffle (rurls.begin (), rurls.end (), rand_gen); + + for (strings::const_iterator i: rurls) { + const string& u (*i); + if (ops.fake_request_specified ()) { auto t (parse_manifest (ops.fake_request (), "task")); -- cgit v1.1