7#include <QtCore/qalgorithms.h>
23 template <
typename UInt>
using IfValidUInt =
24 typename std::enable_if<std::is_unsigned<UInt>::value &&
sizeof(UInt) >=
sizeof(
uint),
bool>
::type;
45 return !(rng1 == rng2);
50 return quint32(_fillRange(
nullptr, 1));
68 x >>= std::numeric_limits<quint64>::digits - std::numeric_limits<double>::digits;
69 return double(
x) / double(
limit);
88 return bounded(highest - lowest) + lowest;
99 return bounded(highest - lowest) + lowest;
107 return bounded(highest - lowest) + lowest;
118 return bounded(highest - lowest) + lowest;
140 template <
typename UInt, IfVal
idUInt<UInt> = true>
146 template <
typename UInt,
size_t N, IfVal
idUInt<UInt> = true>
153 template <
typename ForwardIterator>
169 Q_CORE_EXPORT
void discard(
unsigned long long z);
170 static constexpr result_type min() {
return (std::numeric_limits<result_type>::min)(); }
171 static constexpr result_type max() {
return (std::numeric_limits<result_type>::max)(); }
184 struct InitialRandomData {
191 using RandomEngine =
std::mersenne_twister_engine<
quint32,
192 32,624,397,31,0x9908b0df,11,0xffffffff,7,0x9d2c5680,15,0xefc60000,18,1812433253>;
196 RandomEngine twister;
197 RandomEngine &
engine() {
return twister; }
198 const RandomEngine &
engine()
const {
return twister; }
200 static_assert(std::is_trivially_destructible<RandomEngine>::value,
201 "std::mersenne_twister not trivially destructible as expected");
240 "Overflow. Are you sure you want to skip over 9 quintillion samples?");
244 static constexpr result_type min() {
return (std::numeric_limits<result_type>::min)(); }
245 static constexpr result_type max() {
return (std::numeric_limits<result_type>::max)(); }
266 }
while (
v >= highest);
void discard(unsigned long long z)
static Q_CORE_EXPORT QRandomGenerator64 securelySeeded()
result_type operator()()
Generates a 64-bit random quantity and returns it.
static Q_DECL_CONST_FUNCTION Q_CORE_EXPORT QRandomGenerator64 * global()
static constexpr result_type min()
QRandomGenerator64(std::seed_seq &sseq) noexcept
quint64 result_type
A typedef to the type that operator() returns.
QRandomGenerator64(const QRandomGenerator &other)
quint64 generate()
Generates one 64-bit random value and returns it.
QRandomGenerator64(quint32 seedValue=1)
QRandomGenerator64(const quint32 *begin, const quint32 *end)
QRandomGenerator64(const quint32 *seedBuffer, qsizetype len)
static constexpr result_type max()
QRandomGenerator64(const quint32(&seedBuffer)[N])
static Q_DECL_CONST_FUNCTION Q_CORE_EXPORT QRandomGenerator64 * system()
\inmodule QtCore \reentrant
friend InitialRandomData qt_initial_random_value() noexcept
friend class QRandomGenerator64
static Q_DECL_CONST_FUNCTION QRandomGenerator * system()
\threadsafe
void fillRange(UInt(&buffer)[N])
Generates N 32- or 64-bit quantities (depending on the type UInt) and stores them in the buffer array...
Q_CORE_EXPORT QRandomGenerator & operator=(const QRandomGenerator &other)
qint64 bounded(qint64 highest)
This is an overloaded member function, provided for convenience. It differs from the above function o...
double generateDouble()
Generates one random qreal in the canonical range [0, 1) (that is, inclusive of zero and exclusive of...
quint64 bounded(quint64 lowest, unsigned highest)
This is an overloaded member function, provided for convenience. It differs from the above function o...
Q_CORE_EXPORT void discard(unsigned long long z)
Discards the next z entries from the sequence.
QRandomGenerator(quint32 seedValue=1)
Initializes this QRandomGenerator object with the value seedValue as the seed.
void generate(quint32 *begin, quint32 *end)
This is an overloaded member function, provided for convenience. It differs from the above function o...
QRandomGenerator(const quint32 *seedBuffer, qsizetype len)
This is an overloaded member function, provided for convenience. It differs from the above function o...
quint32 generate()
Generates a 32-bit random quantity and returns it.
static Q_DECL_CONST_FUNCTION QRandomGenerator * global()
\threadsafe
int bounded(int highest)
This is an overloaded member function, provided for convenience. It differs from the above function o...
quint64 generate64()
Generates a 64-bit random quantity and returns it.
static constexpr result_type max()
Returns the maximum value that QRandomGenerator may ever generate.
qint64 bounded(int lowest, qint64 highest)
double bounded(double highest)
Generates one random double in the range between 0 (inclusive) and highest (exclusive).
quint64 bounded(quint64 lowest, quint64 highest)
This is an overloaded member function, provided for convenience. It differs from the above function o...
quint32 result_type
A typedef to the type that operator() returns.
friend Q_CORE_EXPORT bool operator==(const QRandomGenerator &rng1, const QRandomGenerator &rng2)
Returns true if the two engines rng1 and rng2 are at the same state or if they are both reading from ...
void generate(ForwardIterator begin, ForwardIterator end)
Generates 32-bit quantities and stores them in the range between begin and end.
quint32 bounded(quint32 lowest, quint32 highest)
This is an overloaded member function, provided for convenience. It differs from the above function o...
void seed(std::seed_seq &sseq) noexcept
This is an overloaded member function, provided for convenience. It differs from the above function o...
static constexpr result_type min()
Returns the minimum value that QRandomGenerator may ever generate.
qint64 bounded(qint64 lowest, qint64 highest)
This is an overloaded member function, provided for convenience. It differs from the above function o...
quint32 bounded(quint32 highest)
This is an overloaded member function, provided for convenience. It differs from the above function o...
friend bool operator!=(const QRandomGenerator &rng1, const QRandomGenerator &rng2)
Returns true if the two engines rng1 and rng2 are at different states or if one of them is reading fr...
QRandomGenerator(const quint32(&seedBuffer)[N])
This is an overloaded member function, provided for convenience. It differs from the above function o...
quint64 bounded(unsigned lowest, quint64 highest)
static QRandomGenerator securelySeeded()
Returns a new QRandomGenerator object that was securely seeded with QRandomGenerator::system().
result_type operator()()
Generates a 32-bit random quantity and returns it.
qint64 bounded(qint64 lowest, int highest)
int bounded(int lowest, int highest)
This is an overloaded member function, provided for convenience. It differs from the above function o...
void fillRange(UInt *buffer, qsizetype count)
Generates count 32- or 64-bit quantities (depending on the type UInt) and stores them in the buffer p...
void seed(quint32 s=1)
Reseeds this object using the value seed as the seed.
Combined button and popup list for selecting options.
QT_POPCOUNT_RELAXED_CONSTEXPR uint qCountLeadingZeroBits(quint32 v) noexcept
#define Q_DECL_CONST_FUNCTION
EGLOutputLayerEXT EGLint EGLAttrib value
[5]
GLsizei const GLfloat * v
[13]
GLuint GLfloat GLfloat GLfloat GLfloat GLfloat z
GLint GLint GLint GLint GLint x
[0]
GLenum GLenum GLsizei count
GLint GLsizei GLsizei GLenum GLenum GLsizei void * data
GLint GLint GLint GLint GLint GLint GLint GLbitfield mask
#define Q_ASSERT_X(cond, x, msg)
QtPrivate::QRegularExpressionMatchIteratorRangeBasedForIterator begin(const QRegularExpressionMatchIterator &iterator)
unsigned long long quint64
std::seed_seq sseq(seedBuffer, seedBuffer+len)
[3]