diff options
| author | 2019-12-18 01:06:13 +0100 | |
|---|---|---|
| committer | 2019-12-22 01:19:23 +0100 | |
| commit | e285f99759c3edd2d7d0cb4ff4280b5d2fd984da (patch) | |
| tree | 2ebdffb0218632b603e651b0e99234d330f530ca /die.cpp | |
| parent | 0499b503e8ad9c5820df115569effaca8a957777 (diff) | |
| download | OneRoll-e285f99759c3edd2d7d0cb4ff4280b5d2fd984da.tar.gz OneRoll-e285f99759c3edd2d7d0cb4ff4280b5d2fd984da.zip | |
Performance improvement: mt19937 is not static
Diffstat (limited to 'die.cpp')
| -rw-r--r-- | die.cpp | 11 |
1 files changed, 6 insertions, 5 deletions
@@ -27,6 +27,9 @@ #include <QUuid> #include <chrono> +std::mt19937 Die::s_rng= std::mt19937( + static_cast<unsigned long long>(std::chrono::high_resolution_clock::now().time_since_epoch().count())); + Die::Die() : m_uuid(QUuid::createUuid().toString(QUuid::WithoutBraces)) , m_hasValue(false) @@ -36,8 +39,6 @@ Die::Die() , m_color("") , m_op(Die::PLUS) //,m_mt(m_randomDevice) { - auto seed= std::chrono::high_resolution_clock::now().time_since_epoch().count(); - m_rng= std::mt19937(quintptr(this) + static_cast<unsigned long long>(seed)); } Die::Die(const Die& die) { @@ -52,8 +53,8 @@ Die::Die(const Die& die) m_base= die.m_base; m_color= die.getColor(); m_op= die.getOp(); - auto seed= std::chrono::high_resolution_clock::now().time_since_epoch().count(); - m_rng= std::mt19937(quintptr(this) + static_cast<unsigned long long>(seed)); + // auto seed= std::chrono::high_resolution_clock::now().time_since_epoch().count(); + // m_rng= std::mt19937(quintptr(this) + static_cast<unsigned long long>(seed)); } void Die::setValue(qint64 r) @@ -146,7 +147,7 @@ void Die::roll(bool adding) { // quint64 value=(qrand()%m_faces)+m_base; std::uniform_int_distribution<qint64> dist(m_base, m_maxValue); - qint64 value= dist(m_rng); + qint64 value= dist(s_rng); if((adding) || (m_rollResult.isEmpty())) { insertRollValue(value); |