Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Removing RngStream
[simgrid.git] / examples / s4u / app-bittorrent / s4u-tracker.cpp
index 0c14622..390020a 100644 (file)
@@ -1,4 +1,4 @@
-/* Copyright (c) 2012-2018. The SimGrid Team.
+/* Copyright (c) 2012-2019. The SimGrid Team.
  * All rights reserved.                                                     */
 
 /* This program is free software; you can redistribute it and/or modify it
@@ -6,7 +6,6 @@
 
 #include "s4u-tracker.hpp"
 #include <algorithm>
-#include <xbt/RngStream.h>
 
 XBT_LOG_NEW_DEFAULT_CATEGORY(s4u_bt_tracker, "Messages specific for the tracker");
 
@@ -17,14 +16,12 @@ Tracker::Tracker(std::vector<std::string> args)
   // Retrieving end time
   try {
     deadline = std::stod(args[1]);
-  } catch (std::invalid_argument& ia) {
-    throw std::invalid_argument(std::string("Invalid deadline:") + args[1].c_str());
+  } catch (const std::invalid_argument&) {
+    throw std::invalid_argument("Invalid deadline:" + args[1]);
   }
   xbt_assert(deadline > 0, "Wrong deadline supplied");
 
-  stream = simgrid::s4u::this_actor::get_host()->extension<HostBittorrent>()->getStream();
-
-  mailbox = simgrid::s4u::Mailbox::byName(TRACKER_MAILBOX);
+  mailbox = simgrid::s4u::Mailbox::by_name(TRACKER_MAILBOX);
 
   XBT_INFO("Tracker launched.");
 }
@@ -55,8 +52,9 @@ void Tracker::operator()()
       while (tried < max_tries) {
         do {
           next_peer = known_peers.begin();
-          std::advance(next_peer, RngStream_RandInt(stream, 0, nb_known_peers - 1));
-        } while (ta->getPeers()->find(*next_peer) != ta->getPeers()->end());
+          std::uniform_int_distribution<int> dist(0, nb_known_peers - 1);
+          std::advance(next_peer, dist(generator));
+        } while (ta->getPeers().find(*next_peer) != ta->getPeers().end());
         ta->addPeer(*next_peer);
         tried++;
       }