util: seed the PRNG with more entropy
Change-Id: I0e54079bac039db0a10b2f443a3b02b85dd2bb68
diff --git a/ndn-cxx/util/random.cpp b/ndn-cxx/util/random.cpp
index 5358e23..140b23b 100644
--- a/ndn-cxx/util/random.cpp
+++ b/ndn-cxx/util/random.cpp
@@ -1,6 +1,6 @@
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
/*
- * Copyright (c) 2013-2018 Regents of the University of California.
+ * Copyright (c) 2013-2019 Regents of the University of California.
*
* This file is part of ndn-cxx library (NDN C++ library with eXperimental eXtensions).
*
@@ -55,8 +55,14 @@
static std::mt19937&
getRandomGenerator()
{
- static std::mt19937 rng{std::random_device{}()};
- return rng;
+ static optional<std::mt19937> rng;
+ if (!rng) {
+ std::random_device rd;
+ // seed with 256 bits of entropy
+ std::seed_seq seeds{rd(), rd(), rd(), rd(), rd(), rd(), rd(), rd()};
+ rng.emplace(seeds);
+ }
+ return *rng;
}
uint32_t