aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--bbot/agent/agent.cxx17
1 files 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> // thread::hardware_concurrency()
#include <random>
#include <iomanip> // setw()
+#include <numeric> // iota()
#include <iostream>
#include <system_error> // 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<unsigned int> (50, 60) (g);
+ return std::uniform_int_distribution<unsigned int> (50, 60) (rand_gen);
};
optional<interactive_mode> 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<strings::const_iterator> 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<task_manifest> (ops.fake_request (), "task"));