summaryrefslogtreecommitdiffstats
path: root/src/corelib/global/qrandom.h
diff options
context:
space:
mode:
Diffstat (limited to 'src/corelib/global/qrandom.h')
-rw-r--r--src/corelib/global/qrandom.h28
1 files changed, 18 insertions, 10 deletions
diff --git a/src/corelib/global/qrandom.h b/src/corelib/global/qrandom.h
index bde64646a4..46d3e0e152 100644
--- a/src/corelib/global/qrandom.h
+++ b/src/corelib/global/qrandom.h
@@ -44,6 +44,13 @@
#include <algorithm> // for std::generate
#include <random> // for std::mt19937
+#ifdef min
+# undef min
+#endif
+#ifdef max
+# undef max
+#endif
+
QT_BEGIN_NAMESPACE
class QRandomGenerator
@@ -55,10 +62,10 @@ public:
QRandomGenerator(quint32 seedValue = 1)
: QRandomGenerator(&seedValue, 1)
{}
- template <qssize_t N> QRandomGenerator(const quint32 (&seedBuffer)[N])
+ template <qsizetype N> QRandomGenerator(const quint32 (&seedBuffer)[N])
: QRandomGenerator(seedBuffer, seedBuffer + N)
{}
- QRandomGenerator(const quint32 *seedBuffer, qssize_t len)
+ QRandomGenerator(const quint32 *seedBuffer, qsizetype len)
: QRandomGenerator(seedBuffer, seedBuffer + len)
{}
Q_CORE_EXPORT QRandomGenerator(std::seed_seq &sseq) Q_DECL_NOTHROW;
@@ -131,7 +138,7 @@ public:
}
template <typename UInt, IfValidUInt<UInt> = true>
- void fillRange(UInt *buffer, qssize_t count)
+ void fillRange(UInt *buffer, qsizetype count)
{
_fillRange(buffer, buffer + count);
}
@@ -160,8 +167,8 @@ public:
void seed(quint32 s = 1) { *this = { s }; }
void seed(std::seed_seq &sseq) Q_DECL_NOTHROW { *this = { sseq }; }
Q_CORE_EXPORT void discard(unsigned long long z);
- static Q_DECL_CONSTEXPR result_type min() { return (std::numeric_limits<result_type>::min)(); }
- static Q_DECL_CONSTEXPR result_type max() { return (std::numeric_limits<result_type>::max)(); }
+ static Q_DECL_CONSTEXPR result_type min() { return std::numeric_limits<result_type>::min(); }
+ static Q_DECL_CONSTEXPR result_type max() { return std::numeric_limits<result_type>::max(); }
static inline Q_DECL_CONST_FUNCTION QRandomGenerator *system();
static inline Q_DECL_CONST_FUNCTION QRandomGenerator *global();
@@ -177,7 +184,8 @@ private:
friend class QRandomGenerator64;
struct SystemGenerator;
struct SystemAndGlobalGenerators;
- typedef std::mt19937 RandomEngine;
+ using RandomEngine = std::mersenne_twister_engine<quint32,
+ 32,624,397,31,0x9908b0df,11,0xffffffff,7,0x9d2c5680,15,0xefc60000,18,1812433253>;
union Storage {
uint dummy;
@@ -214,10 +222,10 @@ public:
QRandomGenerator64(quint32 seedValue = 1)
: QRandomGenerator(seedValue)
{}
- template <qssize_t N> QRandomGenerator64(const quint32 (&seedBuffer)[N])
+ template <qsizetype N> QRandomGenerator64(const quint32 (&seedBuffer)[N])
: QRandomGenerator(seedBuffer)
{}
- QRandomGenerator64(const quint32 *seedBuffer, qssize_t len)
+ QRandomGenerator64(const quint32 *seedBuffer, qsizetype len)
: QRandomGenerator(seedBuffer, len)
{}
QRandomGenerator64(std::seed_seq &sseq) Q_DECL_NOTHROW
@@ -235,8 +243,8 @@ public:
QRandomGenerator::discard(z * 2);
}
- static Q_DECL_CONSTEXPR result_type min() { return (std::numeric_limits<result_type>::min)(); }
- static Q_DECL_CONSTEXPR result_type max() { return (std::numeric_limits<result_type>::max)(); }
+ static Q_DECL_CONSTEXPR result_type min() { return std::numeric_limits<result_type>::min(); }
+ static Q_DECL_CONSTEXPR result_type max() { return std::numeric_limits<result_type>::max(); }
static Q_DECL_CONST_FUNCTION Q_CORE_EXPORT QRandomGenerator64 *system();
static Q_DECL_CONST_FUNCTION Q_CORE_EXPORT QRandomGenerator64 *global();
static Q_CORE_EXPORT QRandomGenerator64 securelySeeded();