QRandomGenerator64 Class

QRandomGenerator64 类允许从高质量、无种子随机数生成器中获取 64 位随机值。更多

头文件: #include <QRandomGenerator64>
CMake: find_package(Qt6 REQUIRED COMPONENTS Core)
target_link_libraries(mytarget PRIVATE Qt6::Core)
qmake: QT += core
继承: QRandomGenerator

公共类型

公共函数

quint64 generate()
QRandomGenerator64::result_type operator()()

详细说明

QRandomGenerator64 是围绕QRandomGenerator 的一个简单适配类,它使QRandomGenerator::generate64() 函数成为operator()() 的默认函数,而不是返回 32 位数量的函数。该类旨在与需要 64 位数量而不是 32 位数量的标准库算法结合使用。

在所有其他方面,该类都是相同的。更多信息请参阅QRandomGenerator 文档。

另请参见 QRandomGenerator

成员类型文档

QRandomGenerator64::result_type

operator() 返回类型的类型定义。即 quint64。

另请参见 operator()。

成员函数文档

quint64 QRandomGenerator64::generate()

生成一个 64 位随机值并返回。

关于转换为带符号整数的注意事项:此函数返回的所有位都是随机的,因此最有意义位被置位的概率为 50%。如果希望将返回值转换为 qint64 并保持正值,则应屏蔽符号位:

    qint64 value = QRandomGenerator64::global()->generate() & std::numeric_limits<qint64>::max();

另请参见 QRandomGeneratorQRandomGenerator::generate64()。

QRandomGenerator64::result_type QRandomGenerator64::operator()()

生成并返回一个 64 位随机数。

另请参阅 QRandomGenerator::generate() 和QRandomGenerator::generate64()。

© 2025 The Qt Company Ltd. Documentation contributions included herein are the copyrights of their respective owners. The documentation provided herein is licensed under the terms of the GNU Free Documentation License version 1.3 as published by the Free Software Foundation. Qt and respective logos are trademarks of The Qt Company Ltd. in Finland and/or other countries worldwide. All other trademarks are property of their respective owners.