Qt
Internal/Contributor docs for the Qt SDK. <b>Note:</b> These are NOT official API docs; those are found <a href='https://doc.qt.io/'>here</a>.
Loading...
Searching...
No Matches
QRandomGenerator64 Class Reference

\inmodule QtCore More...

#include <qrandom.h>

+ Inheritance diagram for QRandomGenerator64:
+ Collaboration diagram for QRandomGenerator64:

Public Types

typedef quint64 result_type
 A typedef to the type that operator() returns.
 
- Public Types inherited from QRandomGenerator
typedef quint32 result_type
 A typedef to the type that operator() returns.
 

Public Member Functions

quint64 generate ()
 Generates one 64-bit random value and returns it.
 
result_type operator() ()
 Generates a 64-bit random quantity and returns it.
 
 QRandomGenerator64 (quint32 seedValue=1)
 
template<qsizetype N>
 QRandomGenerator64 (const quint32(&seedBuffer)[N])
 
 QRandomGenerator64 (const quint32 *seedBuffer, qsizetype len)
 
 QRandomGenerator64 (std::seed_seq &sseq) noexcept
 
 QRandomGenerator64 (const quint32 *begin, const quint32 *end)
 
 QRandomGenerator64 (const QRandomGenerator &other)
 
void discard (unsigned long long z)
 
quint32 generate ()
 Generates a 32-bit random quantity and returns it.
 
template<typename ForwardIterator >
void generate (ForwardIterator begin, ForwardIterator end)
 Generates 32-bit quantities and stores them in the range between begin and end.
 
void generate (quint32 *begin, quint32 *end)
 This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
 
- Public Member Functions inherited from QRandomGenerator
 QRandomGenerator (quint32 seedValue=1)
 Initializes this QRandomGenerator object with the value seedValue as the seed.
 
template<qsizetype N>
 QRandomGenerator (const quint32(&seedBuffer)[N])
 This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.Initializes this QRandomGenerator object with the values found in the array seedBuffer as the seed.
 
 QRandomGenerator (const quint32 *seedBuffer, qsizetype len)
 This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.Initializes this QRandomGenerator object with len values found in the array seedBuffer as the seed.
 
Q_CORE_EXPORT QRandomGenerator (std::seed_seq &sseq) noexcept
 This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.Initializes this QRandomGenerator object with the seed sequence sseq as the seed.
 
Q_CORE_EXPORT QRandomGenerator (const quint32 *begin, const quint32 *end)
 This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.Initializes this QRandomGenerator object with the values found in the range from begin to end as the seed.
 
Q_CORE_EXPORT QRandomGenerator (const QRandomGenerator &other)
 Creates a copy of the generator state in the other object.
 
Q_CORE_EXPORT QRandomGeneratoroperator= (const QRandomGenerator &other)
 
quint32 generate ()
 Generates a 32-bit random quantity and returns it.
 
quint64 generate64 ()
 Generates a 64-bit random quantity and returns it.
 
double generateDouble ()
 Generates one random qreal in the canonical range [0, 1) (that is, inclusive of zero and exclusive of 1).
 
double bounded (double highest)
 Generates one random double in the range between 0 (inclusive) and highest (exclusive).
 
quint32 bounded (quint32 highest)
 This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.Generates one random 32-bit quantity in the range between 0 (inclusive) and highest (exclusive).
 
quint32 bounded (quint32 lowest, quint32 highest)
 This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.Generates one random 32-bit quantity in the range between lowest (inclusive) and highest (exclusive).
 
int bounded (int highest)
 This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.Generates one random 32-bit quantity in the range between 0 (inclusive) and highest (exclusive).
 
int bounded (int lowest, int highest)
 This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.Generates one random 32-bit quantity in the range between lowest (inclusive) and highest (exclusive), both of which may be negative, but highest must be greater than lowest.
 
quint64 bounded (quint64 highest)
 This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.Generates one random 64-bit quantity 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 only in what argument(s) it accepts.Generates one random 64-bit quantity in the range between lowest (inclusive) and highest (exclusive).
 
qint64 bounded (qint64 highest)
 This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.Generates one random 64-bit quantity in the range between 0 (inclusive) and highest (exclusive).
 
qint64 bounded (qint64 lowest, qint64 highest)
 This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.Generates one random 64-bit quantity in the range between lowest (inclusive) and highest (exclusive), both of which may be negative, but highest must be greater than lowest.
 
qint64 bounded (int lowest, qint64 highest)
 
qint64 bounded (qint64 lowest, int highest)
 
quint64 bounded (unsigned lowest, quint64 highest)
 
quint64 bounded (quint64 lowest, unsigned highest)
 This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.This function exists to help with overload resolution when the types of the parameters don't exactly match.
 
template<typename UInt , IfValidUInt< UInt > = true>
void fillRange (UInt *buffer, qsizetype count)
 Generates count 32- or 64-bit quantities (depending on the type UInt) and stores them in the buffer pointed by buffer.
 
template<typename UInt , size_t N, IfValidUInt< UInt > = true>
void fillRange (UInt(&buffer)[N])
 Generates N 32- or 64-bit quantities (depending on the type UInt) and stores them in the buffer array.
 
template<typename ForwardIterator >
void generate (ForwardIterator begin, ForwardIterator end)
 Generates 32-bit quantities and stores them in the range between begin and end.
 
void generate (quint32 *begin, quint32 *end)
 This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
 
result_type operator() ()
 Generates a 32-bit random quantity and returns it.
 
void seed (quint32 s=1)
 Reseeds this object using the value seed as the seed.
 
void seed (std::seed_seq &sseq) noexcept
 This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.Reseeds this object using the seed sequence seed as the seed.
 
Q_CORE_EXPORT void discard (unsigned long long z)
 Discards the next z entries from the sequence.
 

Static Public Member Functions

static constexpr result_type min ()
 
static constexpr result_type max ()
 
static Q_DECL_CONST_FUNCTION Q_CORE_EXPORT QRandomGenerator64system ()
 
static Q_DECL_CONST_FUNCTION Q_CORE_EXPORT QRandomGenerator64global ()
 
static Q_CORE_EXPORT QRandomGenerator64 securelySeeded ()
 
- Static Public Member Functions inherited from QRandomGenerator
static constexpr result_type min ()
 Returns the minimum value that QRandomGenerator may ever generate.
 
static constexpr result_type max ()
 Returns the maximum value that QRandomGenerator may ever generate.
 
static Q_DECL_CONST_FUNCTION QRandomGeneratorsystem ()
 \threadsafe
 
static Q_DECL_CONST_FUNCTION QRandomGeneratorglobal ()
 \threadsafe
 
static QRandomGenerator securelySeeded ()
 Returns a new QRandomGenerator object that was securely seeded with QRandomGenerator::system().
 

Additional Inherited Members

- Protected Types inherited from QRandomGenerator
enum  System
 
- Protected Member Functions inherited from QRandomGenerator
 QRandomGenerator (System)
 

Detailed Description

\inmodule QtCore

Since
5.10

The QRandomGenerator64 class allows one to obtain 64-bit random values from a high-quality, seed-less Random Number Generator.

QRandomGenerator64 is a simple adaptor class around QRandomGenerator, making the QRandomGenerator::generate64() function the default for operator()(), instead of the function that returns 32-bit quantities. This class is intended to be used in conjunction with Standard Library algorithms that need 64-bit quantities instead of 32-bit ones.

In all other aspects, the class is the same. Please refer to QRandomGenerator's documentation for more information.

See also
QRandomGenerator

Definition at line 208 of file qrandom.h.

Member Typedef Documentation

◆ result_type

A typedef to the type that operator() returns.

That is, quint64.

See also
operator()

Definition at line 216 of file qrandom.h.

Constructor & Destructor Documentation

◆ QRandomGenerator64() [1/6]

QRandomGenerator64::QRandomGenerator64 ( quint32 seedValue = 1)
inline

Definition at line 220 of file qrandom.h.

◆ QRandomGenerator64() [2/6]

template<qsizetype N>
QRandomGenerator64::QRandomGenerator64 ( const quint32(&) seedBuffer[N])
inline

Definition at line 223 of file qrandom.h.

◆ QRandomGenerator64() [3/6]

QRandomGenerator64::QRandomGenerator64 ( const quint32 * seedBuffer,
qsizetype len )
inline

Definition at line 226 of file qrandom.h.

◆ QRandomGenerator64() [4/6]

QRandomGenerator64::QRandomGenerator64 ( std::seed_seq & sseq)
inlinenoexcept

Definition at line 229 of file qrandom.h.

◆ QRandomGenerator64() [5/6]

QRandomGenerator64::QRandomGenerator64 ( const quint32 * begin,
const quint32 * end )
inline

Definition at line 232 of file qrandom.h.

◆ QRandomGenerator64() [6/6]

QRandomGenerator64::QRandomGenerator64 ( const QRandomGenerator & other)
inline

Definition at line 235 of file qrandom.h.

Member Function Documentation

◆ discard()

void QRandomGenerator64::discard ( unsigned long long z)
inline

Definition at line 237 of file qrandom.h.

References QRandomGenerator::discard(), and Q_ASSERT_X.

+ Here is the call graph for this function:

◆ generate() [1/4]

quint32 QRandomGenerator::generate ( )
inline

Generates a 32-bit random quantity and returns it.

See also
{QRandomGenerator::operator()}{operator()()}, generate64()

Definition at line 48 of file qrandom.h.

◆ generate() [2/4]

quint64 QRandomGenerator64::generate ( )
inline

Generates one 64-bit random value and returns it.

Note about casting to a signed integer: all bits returned by this function are random, so there's a 50% chance that the most significant bit will be set. If you wish to cast the returned value to qint64 and keep it positive, you should mask the sign bit off:

See also
QRandomGenerator, QRandomGenerator::generate64()

Definition at line 214 of file qrandom.h.

References QRandomGenerator::generate64().

+ Here is the call graph for this function:

◆ generate() [3/4]

template<typename ForwardIterator >
template< typename ForwardIterator > void QRandomGenerator::generate ( ForwardIterator begin,
ForwardIterator end )
inline

Generates 32-bit quantities and stores them in the range between begin and end.

This function is equivalent to (and is implemented as):

This function complies with the requirements for the function \l{http://en.cppreference.com/w/cpp/numeric/random/seed_seq/generate}{std::seed_seq::generate}, which requires unsigned 32-bit integer values.

Note that if the [begin, end) range refers to an area that can store more than 32 bits per element, the elements will still be initialized with only 32 bits of data. Any other bits will be zero. To fill the range with 64 bit quantities, one can write:

If the range refers to contiguous memory (such as an array or the data from a QList), the fillRange() function may be used too.

See also
fillRange()

Definition at line 154 of file qrandom.h.

◆ generate() [4/4]

void QRandomGenerator::generate ( quint32 * begin,
quint32 * end )
inline

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

Same as the other overload, but more efficiently fills begin to end.

Definition at line 159 of file qrandom.h.

◆ global()

QRandomGenerator64 * QRandomGenerator64::global ( )
static

Definition at line 1134 of file qrandom.cpp.

References QRandomGenerator::SystemAndGlobalGenerators::globalNoInit(), Q_LIKELY, QRandomGenerator::SystemAndGlobalGenerators::securelySeed(), and SystemRNG.

Referenced by QRandomGenerator::global().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ max()

static constexpr result_type QRandomGenerator64::max ( )
inlinestaticconstexpr

Definition at line 245 of file qrandom.h.

◆ min()

static constexpr result_type QRandomGenerator64::min ( )
inlinestaticconstexpr

Definition at line 244 of file qrandom.h.

◆ operator()()

result_type QRandomGenerator64::operator() ( )
inline

Generates a 64-bit random quantity and returns it.

See also
QRandomGenerator::generate(), QRandomGenerator::generate64()

Definition at line 217 of file qrandom.h.

References QRandomGenerator::generate64().

+ Here is the call graph for this function:

◆ securelySeeded()

QRandomGenerator64 QRandomGenerator64::securelySeeded ( )
static

Definition at line 1152 of file qrandom.cpp.

References QRandomGenerator::SystemAndGlobalGenerators::securelySeed().

Referenced by QRandomGenerator::securelySeeded().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ system()

QRandomGenerator64 * QRandomGenerator64::system ( )
static

Definition at line 1127 of file qrandom.cpp.

References Q_ASSERT, QRandomGenerator::SystemAndGlobalGenerators::system(), and SystemRNG.

Referenced by QRandomGenerator::system().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

The documentation for this class was generated from the following files: