[][src]Struct qt_core::QRandomGenerator

#[repr(C)]pub struct QRandomGenerator { /* fields omitted */ }

The QRandomGenerator class allows one to obtain random values from a high-quality Random Number Generator.

C++ class: QRandomGenerator.

C++ documentation:

The QRandomGenerator class allows one to obtain random values from a high-quality Random Number Generator.

QRandomGenerator may be used to generate random values from a high-quality random number generator. Like the C++ random engines, QRandomGenerator can be seeded with user-provided values through the constructor. When seeded, the sequence of numbers generated by this class is deterministic. That is to say, given the same seed data, QRandomGenerator will generate the same sequence of numbers. But given different seeds, the results should be considerably different.

QRandomGenerator::securelySeeded() can be used to create a QRandomGenerator that is securely seeded with QRandomGenerator::system(), meaning that the sequence of numbers it generates cannot be easily predicted. Additionally, QRandomGenerator::global() returns a global instance of QRandomGenerator that Qt will ensure to be securely seeded. This object is thread-safe, may be shared for most uses, and is always seeded from QRandomGenerator::system()

QRandomGenerator::system() may be used to access the system's cryptographically-safe random generator. On Unix systems, it's equivalent to reading from /dev/urandom or the getrandom() or getentropy() system calls.

The class can generate 32-bit or 64-bit quantities, or fill an array of those. The most common way of generating new values is to call the generate(), generate64() or fillRange() functions. One would use it as:

quint32 value = QRandomGenerator::global()->generate();

Additionally, it provides a floating-point function generateDouble() that returns a number in the range [0, 1) (that is, inclusive of zero and exclusive of 1). There's also a set of convenience functions that facilitate obtaining a random number in a bounded, integral range.

Methods

impl QRandomGenerator[src]

pub unsafe fn bounded_double(&self, highest: c_double) -> c_double[src]

This is supported on cpp_lib_version="5.11.3" or cpp_lib_version="5.12.2" or cpp_lib_version="5.13.0" or cpp_lib_version="5.14.0" only.

Generates one random double in the range between 0 (inclusive) and highest (exclusive). This function is equivalent to and is implemented as:

Calls C++ function: double QRandomGenerator::bounded(double highest).

C++ documentation:

Generates one random double in the range between 0 (inclusive) and highest (exclusive). This function is equivalent to and is implemented as:


  return generateDouble() * highest;

See also generateDouble() and bounded().

pub unsafe fn bounded_u32(&self, highest: u32) -> u32[src]

This is supported on cpp_lib_version="5.11.3" or cpp_lib_version="5.12.2" or cpp_lib_version="5.13.0" or cpp_lib_version="5.14.0" only.

This is an overloaded function.

Calls C++ function: quint32 QRandomGenerator::bounded(quint32 highest).

C++ documentation:

This is an overloaded function.

Generates one random 32-bit quantity in the range between 0 (inclusive) and highest (exclusive). The same result may also be obtained by using std::uniform_int_distribution with parameters 0 and highest - 1. That class can also be used to obtain quantities larger than 32 bits.

For example, to obtain a value between 0 and 255 (inclusive), one would write:

quint32 v = QRandomGenerator::bounded(256);

Naturally, the same could also be obtained by masking the result of generate() to only the lower 8 bits. Either solution is as efficient.

Note that this function cannot be used to obtain values in the full 32-bit range of quint32. Instead, use generate().

See also generate(), generate64(), and generateDouble().

pub unsafe fn bounded_int(&self, highest: c_int) -> c_int[src]

This is supported on cpp_lib_version="5.11.3" or cpp_lib_version="5.12.2" or cpp_lib_version="5.13.0" or cpp_lib_version="5.14.0" only.

This is an overloaded function.

Calls C++ function: int QRandomGenerator::bounded(int highest).

C++ documentation:

This is an overloaded function.

Generates one random 32-bit quantity in the range between 0 (inclusive) and highest (exclusive). highest must not be negative.

Note that this function cannot be used to obtain values in the full 32-bit range of int. Instead, use generate() and cast to int.

See also generate(), generate64(), and generateDouble().

pub unsafe fn bounded_2_u32(&self, lowest: u32, highest: u32) -> u32[src]

This is supported on cpp_lib_version="5.11.3" or cpp_lib_version="5.12.2" or cpp_lib_version="5.13.0" or cpp_lib_version="5.14.0" only.

This is an overloaded function.

Calls C++ function: quint32 QRandomGenerator::bounded(quint32 lowest, quint32 highest).

C++ documentation:

This is an overloaded function.

Generates one random 32-bit quantity in the range between lowest (inclusive) and highest (exclusive). The same result may also be obtained by using std::uniform_int_distribution with parameters lowest and \a highest - 1. That class can also be used to obtain quantities larger than 32 bits.

For example, to obtain a value between 1000 (incl.) and 2000 (excl.), one would write:

quint32 v = QRandomGenerator::bounded(1000, 2000);

Note that this function cannot be used to obtain values in the full 32-bit range of quint32. Instead, use generate().

See also generate(), generate64(), and generateDouble().

pub unsafe fn bounded_2_int(&self, lowest: c_int, highest: c_int) -> c_int[src]

This is supported on cpp_lib_version="5.11.3" or cpp_lib_version="5.12.2" or cpp_lib_version="5.13.0" or cpp_lib_version="5.14.0" only.

This is an overloaded function.

Calls C++ function: int QRandomGenerator::bounded(int lowest, int highest).

C++ documentation:

This is an overloaded function.

Generates one random 32-bit quantity in the range between lowest (inclusive) and highest (exclusive), both of which may be negative.

Note that this function cannot be used to obtain values in the full 32-bit range of int. Instead, use generate() and cast to int.

See also generate(), generate64(), and generateDouble().

pub unsafe fn call(&self) -> c_uint[src]

This is supported on cpp_lib_version="5.11.3" or cpp_lib_version="5.12.2" or cpp_lib_version="5.13.0" or cpp_lib_version="5.14.0" only.

Generates a 32-bit random quantity and returns it.

Calls C++ function: unsigned int QRandomGenerator::operator()().

C++ documentation:

Generates a 32-bit random quantity and returns it.

See also generate() and generate64().

pub unsafe fn copy_from(
    &self,
    other: impl CastInto<Ref<QRandomGenerator>>
) -> Ref<QRandomGenerator>
[src]

This is supported on cpp_lib_version="5.11.3" or cpp_lib_version="5.12.2" or cpp_lib_version="5.13.0" or cpp_lib_version="5.14.0" only.

Copy-assignment operator.

Calls C++ function: QRandomGenerator& QRandomGenerator::operator=(const QRandomGenerator& other).

C++ documentation:

Copy-assignment operator.

pub unsafe fn discard(&self, z: c_ulonglong)[src]

This is supported on cpp_lib_version="5.11.3" or cpp_lib_version="5.12.2" or cpp_lib_version="5.13.0" or cpp_lib_version="5.14.0" only.

Discards the next z entries from the sequence. This method is equivalent to calling generate() z times and discarding the result, as in:

Calls C++ function: void QRandomGenerator::discard(unsigned long long z).

C++ documentation:

Discards the next z entries from the sequence. This method is equivalent to calling generate() z times and discarding the result, as in:


  while (z--)
      generator.generate();

pub unsafe fn generate_0a(&self) -> u32[src]

This is supported on cpp_lib_version="5.11.3" or cpp_lib_version="5.12.2" or cpp_lib_version="5.13.0" or cpp_lib_version="5.14.0" only.

Generates a 32-bit random quantity and returns it.

Calls C++ function: quint32 QRandomGenerator::generate().

C++ documentation:

Generates a 32-bit random quantity and returns it.

See also operator()() and generate64().

pub unsafe fn generate_2a(&self, begin: *mut u32, end: *mut u32)[src]

This is supported on cpp_lib_version="5.11.3" or cpp_lib_version="5.12.2" or cpp_lib_version="5.13.0" or cpp_lib_version="5.14.0" only.

Calls C++ function: void QRandomGenerator::generate(quint32* begin, quint32* end).

pub unsafe fn generate64(&self) -> u64[src]

This is supported on cpp_lib_version="5.11.3" or cpp_lib_version="5.12.2" or cpp_lib_version="5.13.0" or cpp_lib_version="5.14.0" only.

Generates a 64-bit random quantity and returns it.

Calls C++ function: quint64 QRandomGenerator::generate64().

C++ documentation:

Generates a 64-bit random quantity and returns it.

See also operator()() and generate().

pub unsafe fn generate_double(&self) -> c_double[src]

This is supported on cpp_lib_version="5.11.3" or cpp_lib_version="5.12.2" or cpp_lib_version="5.13.0" or cpp_lib_version="5.14.0" only.

Generates one random qreal in the canonical range [0, 1) (that is, inclusive of zero and exclusive of 1).

Calls C++ function: double QRandomGenerator::generateDouble().

C++ documentation:

Generates one random qreal in the canonical range [0, 1) (that is, inclusive of zero and exclusive of 1).

This function is equivalent to:

QRandomGenerator64 rd; return std::generate_canonical<qreal, std::numeric_limits<qreal>::digits>(rd);

The same may also be obtained by using std::uniform_real_distribution with parameters 0 and 1.

See also generate(), generate64(), and bounded().

pub unsafe fn global() -> Ptr<QRandomGenerator>[src]

This is supported on cpp_lib_version="5.11.3" or cpp_lib_version="5.12.2" or cpp_lib_version="5.13.0" or cpp_lib_version="5.14.0" only.

Returns a pointer to a shared QRandomGenerator that was seeded using securelySeeded(). This function should be used to create random data without the expensive creation of a securely-seeded QRandomGenerator for a specific use or storing the rather large QRandomGenerator object.

Calls C++ function: static QRandomGenerator* QRandomGenerator::global().

C++ documentation:

Returns a pointer to a shared QRandomGenerator that was seeded using securelySeeded(). This function should be used to create random data without the expensive creation of a securely-seeded QRandomGenerator for a specific use or storing the rather large QRandomGenerator object.

For example, the following creates a random RGB color:

return QColor::fromRgb(QRandomGenerator::global()->generate());

Accesses to this object are thread-safe and it may therefore be used in any thread without locks. The object may also be copied and the sequence produced by the copy will be the same as the shared object will produce. Note, however, that if there are other threads accessing the global object, those threads may obtain samples at unpredictable intervals.

Note: This function is thread-safe.

See also securelySeeded() and system().

pub unsafe fn max() -> c_uint[src]

This is supported on cpp_lib_version="5.11.3" or cpp_lib_version="5.12.2" or cpp_lib_version="5.13.0" or cpp_lib_version="5.14.0" only.

Returns the maximum value that QRandomGenerator may ever generate. That is, std::numeric_limits<result_type>::max().

Calls C++ function: static unsigned int QRandomGenerator::max().

C++ documentation:

Returns the maximum value that QRandomGenerator may ever generate. That is, std::numeric_limits<result_type>::max().

See also min() and QRandomGenerator64::max().

pub unsafe fn min() -> c_uint[src]

This is supported on cpp_lib_version="5.11.3" or cpp_lib_version="5.12.2" or cpp_lib_version="5.13.0" or cpp_lib_version="5.14.0" only.

Returns the minimum value that QRandomGenerator may ever generate. That is, 0.

Calls C++ function: static unsigned int QRandomGenerator::min().

C++ documentation:

Returns the minimum value that QRandomGenerator may ever generate. That is, 0.

See also max() and QRandomGenerator64::min().

pub unsafe fn from_u32(seed_value: u32) -> CppBox<QRandomGenerator>[src]

This is supported on cpp_lib_version="5.11.3" or cpp_lib_version="5.12.2" or cpp_lib_version="5.13.0" or cpp_lib_version="5.14.0" only.

Initializes this QRandomGenerator object with the value seedValue as the seed. Two objects constructed or reseeded with the same seed value will produce the same number sequence.

Calls C++ function: [constructor] void QRandomGenerator::QRandomGenerator(quint32 seedValue = …).

C++ documentation:

Initializes this QRandomGenerator object with the value seedValue as the seed. Two objects constructed or reseeded with the same seed value will produce the same number sequence.

See also seed() and securelySeeded().

pub unsafe fn from_u32_longlong(
    seed_buffer: *const u32,
    len: c_longlong
) -> CppBox<QRandomGenerator>
[src]

This is supported on cpp_lib_version="5.11.3" or cpp_lib_version="5.12.2" or cpp_lib_version="5.13.0" or cpp_lib_version="5.14.0" only.

Calls C++ function: [constructor] void QRandomGenerator::QRandomGenerator(const quint32* seedBuffer, long long len).

pub unsafe fn from_2_u32(
    begin: *const u32,
    end: *const u32
) -> CppBox<QRandomGenerator>
[src]

This is supported on cpp_lib_version="5.11.3" or cpp_lib_version="5.12.2" or cpp_lib_version="5.13.0" or cpp_lib_version="5.14.0" only.

This is an overloaded function.

Calls C++ function: [constructor] void QRandomGenerator::QRandomGenerator(const quint32* begin, const quint32* end).

C++ documentation:

This is an overloaded function.

Initializes this QRandomGenerator object with the values found in the range from begin to end as the seed. Two objects constructed or reseeded with the same seed value will produce the same number sequence.

This constructor is equivalent to:

std::seed_seq sseq(begin, end); QRandomGenerator generator(sseq);

See also seed() and securelySeeded().

pub unsafe fn new() -> CppBox<QRandomGenerator>[src]

This is supported on cpp_lib_version="5.11.3" or cpp_lib_version="5.12.2" or cpp_lib_version="5.13.0" or cpp_lib_version="5.14.0" only.

The QRandomGenerator class allows one to obtain random values from a high-quality Random Number Generator.

Calls C++ function: [constructor] void QRandomGenerator::QRandomGenerator().

C++ documentation:

The QRandomGenerator class allows one to obtain random values from a high-quality Random Number Generator.

QRandomGenerator may be used to generate random values from a high-quality random number generator. Like the C++ random engines, QRandomGenerator can be seeded with user-provided values through the constructor. When seeded, the sequence of numbers generated by this class is deterministic. That is to say, given the same seed data, QRandomGenerator will generate the same sequence of numbers. But given different seeds, the results should be considerably different.

QRandomGenerator::securelySeeded() can be used to create a QRandomGenerator that is securely seeded with QRandomGenerator::system(), meaning that the sequence of numbers it generates cannot be easily predicted. Additionally, QRandomGenerator::global() returns a global instance of QRandomGenerator that Qt will ensure to be securely seeded. This object is thread-safe, may be shared for most uses, and is always seeded from QRandomGenerator::system()

QRandomGenerator::system() may be used to access the system's cryptographically-safe random generator. On Unix systems, it's equivalent to reading from /dev/urandom or the getrandom() or getentropy() system calls.

The class can generate 32-bit or 64-bit quantities, or fill an array of those. The most common way of generating new values is to call the generate(), generate64() or fillRange() functions. One would use it as:

quint32 value = QRandomGenerator::global()->generate();

Additionally, it provides a floating-point function generateDouble() that returns a number in the range [0, 1) (that is, inclusive of zero and exclusive of 1). There's also a set of convenience functions that facilitate obtaining a random number in a bounded, integral range.

pub unsafe fn new_copy(
    other: impl CastInto<Ref<QRandomGenerator>>
) -> CppBox<QRandomGenerator>
[src]

This is supported on cpp_lib_version="5.11.3" or cpp_lib_version="5.12.2" or cpp_lib_version="5.13.0" or cpp_lib_version="5.14.0" only.

Creates a copy of the generator state in the other object. If other is QRandomGenerator::system() or a copy of that, this object will also read from the operating system random-generating facilities. In that case, the sequences generated by the two objects will be different.

Calls C++ function: [constructor] void QRandomGenerator::QRandomGenerator(const QRandomGenerator& other).

C++ documentation:

Creates a copy of the generator state in the other object. If other is QRandomGenerator::system() or a copy of that, this object will also read from the operating system random-generating facilities. In that case, the sequences generated by the two objects will be different.

In all other cases, the new QRandomGenerator object will start at the same position in the deterministic sequence as the other object was. Both objects will generate the same sequence from this point on.

For that reason, it is not adviseable to create a copy of QRandomGenerator::global(). If one needs an exclusive deterministic generator, consider instead using securelySeeded() to obtain a new object that shares no relationship with the QRandomGenerator::global().

pub unsafe fn securely_seeded() -> CppBox<QRandomGenerator>[src]

This is supported on cpp_lib_version="5.11.3" or cpp_lib_version="5.12.2" or cpp_lib_version="5.13.0" or cpp_lib_version="5.14.0" only.

Returns a new QRandomGenerator object that was securely seeded with QRandomGenerator::system(). This function will obtain the ideal seed size for the algorithm that QRandomGenerator uses and is therefore the recommended way for creating a new QRandomGenerator object that will be kept for some time.

Calls C++ function: static QRandomGenerator QRandomGenerator::securelySeeded().

C++ documentation:

Returns a new QRandomGenerator object that was securely seeded with QRandomGenerator::system(). This function will obtain the ideal seed size for the algorithm that QRandomGenerator uses and is therefore the recommended way for creating a new QRandomGenerator object that will be kept for some time.

Given the amount of data required to securely seed the deterministic engine, this function is somewhat expensive and should not be used for short-term uses of QRandomGenerator (using it to generate fewer than 2600 bytes of random data is effectively a waste of resources). If the use doesn't require that much data, consider using QRandomGenerator::global() and not storing a QRandomGenerator object instead.

See also global() and system().

pub unsafe fn seed_1a(&self, s: u32)[src]

This is supported on cpp_lib_version="5.11.3" or cpp_lib_version="5.12.2" or cpp_lib_version="5.13.0" or cpp_lib_version="5.14.0" only.

Reseeds this object using the value seed as the seed.

Calls C++ function: void QRandomGenerator::seed(quint32 s = …).

C++ documentation:

Reseeds this object using the value seed as the seed.

pub unsafe fn seed_0a(&self)[src]

This is supported on cpp_lib_version="5.11.3" or cpp_lib_version="5.12.2" or cpp_lib_version="5.13.0" or cpp_lib_version="5.14.0" only.

Reseeds this object using the value seed as the seed.

Calls C++ function: void QRandomGenerator::seed().

C++ documentation:

Reseeds this object using the value seed as the seed.

pub unsafe fn system() -> Ptr<QRandomGenerator>[src]

This is supported on cpp_lib_version="5.11.3" or cpp_lib_version="5.12.2" or cpp_lib_version="5.13.0" or cpp_lib_version="5.14.0" only.

Returns a pointer to a shared QRandomGenerator that always uses the facilities provided by the operating system to generate random numbers. The system facilities are considered to be cryptographically safe on at least the following operating systems: Apple OSes (Darwin), BSDs, Linux, Windows. That may also be the case on other operating systems.

Calls C++ function: static QRandomGenerator* QRandomGenerator::system().

C++ documentation:

Returns a pointer to a shared QRandomGenerator that always uses the facilities provided by the operating system to generate random numbers. The system facilities are considered to be cryptographically safe on at least the following operating systems: Apple OSes (Darwin), BSDs, Linux, Windows. That may also be the case on other operating systems.

They are also possibly backed by a true hardware random number generator. For that reason, the QRandomGenerator returned by this function should not be used for bulk data generation. Instead, use it to seed QRandomGenerator or a random engine from the <random> header.

The object returned by this function is thread-safe and may be used in any thread without locks. It may also be copied and the resulting QRandomGenerator will also access the operating system facilities, but they will not generate the same sequence.

Note: This function is thread-safe.

See also securelySeeded() and global().

Trait Implementations

impl CppDeletable for QRandomGenerator[src]

unsafe fn delete(&self)[src]

The QRandomGenerator class allows one to obtain random values from a high-quality Random Number Generator.

Calls C++ function: [destructor] void QRandomGenerator::~QRandomGenerator().

C++ documentation:

The QRandomGenerator class allows one to obtain random values from a high-quality Random Number Generator.

QRandomGenerator may be used to generate random values from a high-quality random number generator. Like the C++ random engines, QRandomGenerator can be seeded with user-provided values through the constructor. When seeded, the sequence of numbers generated by this class is deterministic. That is to say, given the same seed data, QRandomGenerator will generate the same sequence of numbers. But given different seeds, the results should be considerably different.

QRandomGenerator::securelySeeded() can be used to create a QRandomGenerator that is securely seeded with QRandomGenerator::system(), meaning that the sequence of numbers it generates cannot be easily predicted. Additionally, QRandomGenerator::global() returns a global instance of QRandomGenerator that Qt will ensure to be securely seeded. This object is thread-safe, may be shared for most uses, and is always seeded from QRandomGenerator::system()

QRandomGenerator::system() may be used to access the system's cryptographically-safe random generator. On Unix systems, it's equivalent to reading from /dev/urandom or the getrandom() or getentropy() system calls.

The class can generate 32-bit or 64-bit quantities, or fill an array of those. The most common way of generating new values is to call the generate(), generate64() or fillRange() functions. One would use it as:

quint32 value = QRandomGenerator::global()->generate();

Additionally, it provides a floating-point function generateDouble() that returns a number in the range [0, 1) (that is, inclusive of zero and exclusive of 1). There's also a set of convenience functions that facilitate obtaining a random number in a bounded, integral range.

impl StaticDowncast<QRandomGenerator64> for QRandomGenerator[src]

unsafe fn static_downcast(ptr: Ptr<QRandomGenerator>) -> Ptr<QRandomGenerator64>[src]

Calls C++ function: QRandomGenerator64* static_cast<QRandomGenerator64*>(QRandomGenerator* ptr).

impl StaticUpcast<QRandomGenerator> for QRandomGenerator64[src]

unsafe fn static_upcast(ptr: Ptr<QRandomGenerator64>) -> Ptr<QRandomGenerator>[src]

Calls C++ function: QRandomGenerator* static_cast<QRandomGenerator*>(QRandomGenerator64* ptr).

Auto Trait Implementations

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T, U> CastInto<U> for T where
    U: CastFrom<T>, 
[src]

impl<T> From<T> for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T> StaticUpcast<T> for T[src]

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.