core: use ndn-cxx's getRandomNumberEngine()

Change-Id: I3b5b3ac5238d47ac14481b21d0303c63d0c93b56
diff --git a/core/random.cpp b/core/random.cpp
deleted file mode 100644
index e37e472..0000000
--- a/core/random.cpp
+++ /dev/null
@@ -1,44 +0,0 @@
-/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
-/*
- * Copyright (c) 2014-2019,  Regents of the University of California,
- *                           Arizona Board of Regents,
- *                           Colorado State University,
- *                           University Pierre & Marie Curie, Sorbonne University,
- *                           Washington University in St. Louis,
- *                           Beijing Institute of Technology,
- *                           The University of Memphis.
- *
- * This file is part of NFD (Named Data Networking Forwarding Daemon).
- * See AUTHORS.md for complete list of NFD authors and contributors.
- *
- * NFD is free software: you can redistribute it and/or modify it under the terms
- * of the GNU General Public License as published by the Free Software Foundation,
- * either version 3 of the License, or (at your option) any later version.
- *
- * NFD is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
- * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
- * PURPOSE.  See the GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License along with
- * NFD, e.g., in COPYING.md file.  If not, see <http://www.gnu.org/licenses/>.
- */
-
-#include "random.hpp"
-#include <boost/thread/tss.hpp>
-
-namespace nfd {
-
-std::mt19937&
-getGlobalRng()
-{
-  static boost::thread_specific_ptr<std::mt19937> rng;
-  if (rng.get() == nullptr) {
-    std::random_device rd;
-    // seed with 256 bits of entropy
-    std::seed_seq seeds{rd(), rd(), rd(), rd(), rd(), rd(), rd(), rd()};
-    rng.reset(new std::mt19937(seeds));
-  }
-  return *rng;
-}
-
-} // namespace nfd
diff --git a/core/random.hpp b/core/random.hpp
deleted file mode 100644
index 27e1067..0000000
--- a/core/random.hpp
+++ /dev/null
@@ -1,52 +0,0 @@
-/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
-/*
- * Copyright (c) 2014-2017,  Regents of the University of California,
- *                           Arizona Board of Regents,
- *                           Colorado State University,
- *                           University Pierre & Marie Curie, Sorbonne University,
- *                           Washington University in St. Louis,
- *                           Beijing Institute of Technology,
- *                           The University of Memphis.
- *
- * This file is part of NFD (Named Data Networking Forwarding Daemon).
- * See AUTHORS.md for complete list of NFD authors and contributors.
- *
- * NFD is free software: you can redistribute it and/or modify it under the terms
- * of the GNU General Public License as published by the Free Software Foundation,
- * either version 3 of the License, or (at your option) any later version.
- *
- * NFD is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
- * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
- * PURPOSE.  See the GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License along with
- * NFD, e.g., in COPYING.md file.  If not, see <http://www.gnu.org/licenses/>.
- */
-
-/**
- * \file
- * \brief Declares the global pseudorandom number generator (PRNG) for NFD
- *
- * All random numbers generated by NFD should use this global generator,
- * so that it can be properly seeded when necessary.
- *
- * \warning This PRNG is not suitable for security purposes; security-critical
- *          code must use a cryptographically secure PRNG, such as that provided
- *          by OpenSSL.
- */
-
-#ifndef NFD_CORE_RANDOM_HPP
-#define NFD_CORE_RANDOM_HPP
-
-#include <random>
-
-namespace nfd {
-
-/** \return the global random number generator instance
- */
-std::mt19937&
-getGlobalRng();
-
-} // namespace nfd
-
-#endif // NFD_CORE_RANDOM_HPP
diff --git a/daemon/fw/asf-probing-module.cpp b/daemon/fw/asf-probing-module.cpp
index 63f9867..8a81a77 100644
--- a/daemon/fw/asf-probing-module.cpp
+++ b/daemon/fw/asf-probing-module.cpp
@@ -1,6 +1,6 @@
 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
 /*
- * Copyright (c) 2014-2018,  Regents of the University of California,
+ * Copyright (c) 2014-2019,  Regents of the University of California,
  *                           Arizona Board of Regents,
  *                           Colorado State University,
  *                           University Pierre & Marie Curie, Sorbonne University,
@@ -24,9 +24,10 @@
  */
 
 #include "asf-probing-module.hpp"
-#include "core/random.hpp"
 #include "algorithm.hpp"
 
+#include <ndn-cxx/util/random.hpp>
+
 namespace nfd {
 namespace fw {
 namespace asf {
@@ -186,7 +187,7 @@
 ProbingModule::getRandomNumber(double start, double end)
 {
   std::uniform_real_distribution<double> dist(start, end);
-  return dist(getGlobalRng());
+  return dist(ndn::random::getRandomNumberEngine());
 }
 
 void
diff --git a/daemon/fw/ncc-strategy.cpp b/daemon/fw/ncc-strategy.cpp
index bb96009..df9a41b 100644
--- a/daemon/fw/ncc-strategy.cpp
+++ b/daemon/fw/ncc-strategy.cpp
@@ -25,7 +25,8 @@
 
 #include "ncc-strategy.hpp"
 #include "algorithm.hpp"
-#include "core/random.hpp"
+
+#include <ndn-cxx/util/random.hpp>
 
 namespace nfd {
 namespace fw {
@@ -176,7 +177,7 @@
 
   if (isForwarded) {
     std::uniform_int_distribution<time::nanoseconds::rep> dist(0, pitEntryInfo->maxInterval.count() - 1);
-    time::nanoseconds deferNext = time::nanoseconds(dist(getGlobalRng()));
+    time::nanoseconds deferNext(dist(ndn::random::getRandomNumberEngine()));
     pitEntryInfo->propagateTimer = scheduler::schedule(deferNext,
       bind(&NccStrategy::doPropagate, this, inFaceId, weak_ptr<pit::Entry>(pitEntry)));
   }
diff --git a/daemon/fw/strategy.cpp b/daemon/fw/strategy.cpp
index 4dfe32e..3f364ea 100644
--- a/daemon/fw/strategy.cpp
+++ b/daemon/fw/strategy.cpp
@@ -1,6 +1,6 @@
 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
 /*
- * Copyright (c) 2014-2018,  Regents of the University of California,
+ * Copyright (c) 2014-2019,  Regents of the University of California,
  *                           Arizona Board of Regents,
  *                           Colorado State University,
  *                           University Pierre & Marie Curie, Sorbonne University,
@@ -26,7 +26,6 @@
 #include "strategy.hpp"
 #include "forwarder.hpp"
 #include "core/logger.hpp"
-#include "core/random.hpp"
 
 #include <boost/range/adaptor/map.hpp>
 #include <boost/range/algorithm/copy.hpp>
diff --git a/rib/readvertise/readvertise.cpp b/rib/readvertise/readvertise.cpp
index 4c51a03..454ab20 100644
--- a/rib/readvertise/readvertise.cpp
+++ b/rib/readvertise/readvertise.cpp
@@ -25,7 +25,8 @@
 
 #include "readvertise.hpp"
 #include "core/logger.hpp"
-#include "core/random.hpp"
+
+#include <ndn-cxx/util/random.hpp>
 
 namespace nfd {
 namespace rib {
@@ -38,8 +39,8 @@
 static time::milliseconds
 randomizeTimer(time::milliseconds baseTimer)
 {
-  std::uniform_int_distribution<uint64_t> dist(-5, 5);
-  time::milliseconds newTime = baseTimer + time::milliseconds(dist(getGlobalRng()));
+  std::uniform_int_distribution<> dist(-5, 5);
+  auto newTime = baseTimer + time::milliseconds(dist(ndn::random::getRandomNumberEngine()));
   return std::max(newTime, 0_ms);
 }
 
diff --git a/tests/core/random.t.cpp b/tests/core/random.t.cpp
deleted file mode 100644
index dcd1576..0000000
--- a/tests/core/random.t.cpp
+++ /dev/null
@@ -1,55 +0,0 @@
-/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
-/**
- * Copyright (c) 2014-2016,  Regents of the University of California,
- *                           Arizona Board of Regents,
- *                           Colorado State University,
- *                           University Pierre & Marie Curie, Sorbonne University,
- *                           Washington University in St. Louis,
- *                           Beijing Institute of Technology,
- *                           The University of Memphis.
- *
- * This file is part of NFD (Named Data Networking Forwarding Daemon).
- * See AUTHORS.md for complete list of NFD authors and contributors.
- *
- * NFD is free software: you can redistribute it and/or modify it under the terms
- * of the GNU General Public License as published by the Free Software Foundation,
- * either version 3 of the License, or (at your option) any later version.
- *
- * NFD is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
- * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
- * PURPOSE.  See the GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License along with
- * NFD, e.g., in COPYING.md file.  If not, see <http://www.gnu.org/licenses/>.
- */
-
-#include "core/random.hpp"
-
-#include "tests/test-common.hpp"
-
-#include <boost/thread.hpp>
-
-namespace nfd {
-namespace tests {
-
-BOOST_AUTO_TEST_SUITE(TestRandom)
-
-BOOST_AUTO_TEST_CASE(ThreadLocalRng)
-{
-  std::mt19937* s1 = &getGlobalRng();
-  std::mt19937* s2 = nullptr;
-  boost::thread t([&s2] {
-    s2 = &getGlobalRng();
-  });
-
-  t.join();
-
-  BOOST_CHECK(s1 != nullptr);
-  BOOST_CHECK(s2 != nullptr);
-  BOOST_CHECK(s1 != s2);
-}
-
-BOOST_AUTO_TEST_SUITE_END() // TestRandom
-
-} // namespace tests
-} // namespace nfd
diff --git a/tests/daemon/mgmt/face-manager.t.cpp b/tests/daemon/mgmt/face-manager.t.cpp
index 69b2116..cebbfd4 100644
--- a/tests/daemon/mgmt/face-manager.t.cpp
+++ b/tests/daemon/mgmt/face-manager.t.cpp
@@ -1,6 +1,6 @@
 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
 /*
- * Copyright (c) 2014-2018,  Regents of the University of California,
+ * Copyright (c) 2014-2019,  Regents of the University of California,
  *                           Arizona Board of Regents,
  *                           Colorado State University,
  *                           University Pierre & Marie Curie, Sorbonne University,
@@ -24,7 +24,6 @@
  */
 
 #include "mgmt/face-manager.hpp"
-#include "core/random.hpp"
 #include "face/protocol-factory.hpp"
 
 #include "nfd-manager-common-fixture.hpp"
@@ -38,6 +37,7 @@
 #include <ndn-cxx/mgmt/nfd/face-query-filter.hpp>
 #include <ndn-cxx/mgmt/nfd/face-status.hpp>
 #include <ndn-cxx/net/network-monitor-stub.hpp>
+#include <ndn-cxx/util/random.hpp>
 
 namespace nfd {
 namespace tests {
@@ -109,7 +109,7 @@
   randomizeCounter(const T& counter)
   {
     static std::uniform_int_distribution<typename T::rep> dist;
-    const_cast<T&>(counter).set(dist(getGlobalRng()));
+    const_cast<T&>(counter).set(dist(ndn::random::getRandomNumberEngine()));
   }
 
 protected: