aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/die.cpp
diff options
context:
space:
mode:
authorRenaud G <renaud@rolisteam.org>2020-04-15 22:48:11 +0200
committerRenaud G <renaud@rolisteam.org>2020-04-15 22:48:11 +0200
commita8694975776288e1135935eb99981df3c0cf93d1 (patch)
treef113cb90f9f2917ad7fd74aa944f3d4622041d6b /die.cpp
parent5de6438aa1dae2437adc4f6bf288f3c7bc8a8585 (diff)
downloadOneRoll-a8694975776288e1135935eb99981df3c0cf93d1.tar.gz
OneRoll-a8694975776288e1135935eb99981df3c0cf93d1.zip
Improve init of the seed
Diffstat (limited to 'die.cpp')
-rw-r--r--die.cpp19
1 files changed, 17 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;