diff options
| -rw-r--r-- | die.cpp | 19 | ||||
| -rw-r--r-- | die.h | 2 |
2 files changed, 19 insertions, 2 deletions
@@ -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; @@ -147,6 +147,8 @@ public: QString getUuid() const; void setUuid(const QString& uuid); + static void buildSeed(); + private: QString m_uuid; qint64 m_value= 0; |