core: use C++11 <random> instead of Boost.Random
Change-Id: I8f22965b86c681581762a47995f29f888421a558
Refs: #3599
diff --git a/core/random.cpp b/core/random.cpp
index c398f8d..9c5de40 100644
--- a/core/random.cpp
+++ b/core/random.cpp
@@ -1,6 +1,6 @@
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
/**
- * Copyright (c) 2014-2015, Regents of the University of California,
+ * Copyright (c) 2014-2016, Regents of the University of California,
* Arizona Board of Regents,
* Colorado State University,
* University Pierre & Marie Curie, Sorbonne University,
@@ -28,21 +28,15 @@
namespace nfd {
-static boost::thread_specific_ptr<boost::random::mt19937> g_rng;
-
-boost::random::mt19937&
+std::mt19937&
getGlobalRng()
{
- if (g_rng.get() == nullptr) {
- g_rng.reset(new boost::random::mt19937());
+ static boost::thread_specific_ptr<std::mt19937> rng;
+ if (rng.get() == nullptr) {
+ std::random_device rd;
+ rng.reset(new std::mt19937(rd()));
}
- return *g_rng;
-}
-
-void
-resetGlobalRng()
-{
- g_rng.reset();
+ return *rng;
}
} // namespace nfd
diff --git a/core/random.hpp b/core/random.hpp
index 1515b72..03ae9d3 100644
--- a/core/random.hpp
+++ b/core/random.hpp
@@ -1,12 +1,12 @@
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
/**
- * Copyright (c) 2014, 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
+ * 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.
@@ -24,24 +24,26 @@
*/
/**
- * This file declares the global random number generator
- * All random numbers in NFD should use this global random number generator,
- * so that the generator can be properly seeded when necessary.
+ * This file declares the global pseudorandom number generator (PRNG).
*
- * This random number generator is not suitable for security purposes;
- * security-critical code should use CryptoPP random number generator instead.
+ * All random numbers generated by NFD should use this global generator,
+ * so that it can be properly seeded when necessary.
+ *
+ * This PRNG is not suitable for security purposes; security-critical
+ * code must use a cryptographically secure PRNG, such as those provided
+ * by OpenSSL and Crypto++.
*/
#ifndef NFD_CORE_RANDOM_HPP
#define NFD_CORE_RANDOM_HPP
-#include <boost/random/mersenne_twister.hpp>
+#include <random>
namespace nfd {
/** \return the global random number generator instance
*/
-boost::random::mt19937&
+std::mt19937&
getGlobalRng();
} // namespace nfd