aboutsummaryrefslogtreecommitdiffstatshomepage
diff options
context:
space:
mode:
-rw-r--r--die.cpp19
-rw-r--r--die.h2
2 files changed, 19 insertions, 2 deletions
diff --git a/die.cpp b/die.cpp
index 79a4189..fe39198 100644
--- a/die.cpp
+++ b/die.cpp
@@ -25,10 +25,23 @@
#include <QDateTime>
#include <QDebug>
#include <QUuid>
+#include <algorithm>
#include <chrono>
-std::mt19937 Die::s_rng= std::mt19937(
- static_cast<unsigned long long>(std::chrono::high_resolution_clock::now().time_since_epoch().count()));
+void Die::buildSeed()
+{
+ static bool init= false;
+ if(init)
+ return;
+ std::array<int, std::mt19937::state_size> seed_data;
+ std::random_device r;
+ std::generate_n(seed_data.data(), seed_data.size(), std::ref(r));
+ std::seed_seq seq(std::begin(seed_data), std::end(seed_data));
+ s_rng= std::mt19937(seq);
+ init= true;
+}
+
+std::mt19937 Die::s_rng;
Die::Die()
: m_uuid(QUuid::createUuid().toString(QUuid::WithoutBraces))
@@ -39,7 +52,9 @@ Die::Die()
, m_color("")
, m_op(Die::PLUS) //,m_mt(m_randomDevice)
{
+ buildSeed();
}
+
Die::Die(const Die& die)
{
m_value= die.m_value;
diff --git a/die.h b/die.h
index 0b9ca44..140098b 100644
--- a/die.h
+++ b/die.h
@@ -147,6 +147,8 @@ public:
QString getUuid() const;
void setUuid(const QString& uuid);
+ static void buildSeed();
+
private:
QString m_uuid;
qint64 m_value= 0;