std:: seed_seq
From cppreference.net
C++
Numerics library
| Common mathematical functions | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Mathematical special functions (C++17) | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Mathematical constants (C++20) | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Basic linear algebra algorithms (C++26) | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Data-parallel types (SIMD) (C++26) | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Floating-point environment (C++11) | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Complex numbers | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Numeric array (
valarray
)
|
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Pseudo-random number generation | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Bit manipulation (C++20) | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Saturation arithmetic (C++26) | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Factor operations | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Interpolations | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Generic numeric operations | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| C-style checked integer arithmetic | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Pseudo-random number generation
|
|
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
std::seed_seq
| Member functions | ||||
|
定义于头文件
<random>
|
||
|
class
seed_seq
;
|
(C++11 起) | |
std::seed_seq
消耗一个整数值数据序列,并根据消耗的数据生成指定数量的32位无符号整数值。即使消耗的数值较为接近,生成的值也会均匀分布在整个32位范围内。
它提供了一种方法,能够通过较小的种子或分布不均的初始种子序列,为大量随机数引擎或需要高熵值的生成器进行播种。
std::seed_seq
满足
SeedSequence
的要求。
目录 |
嵌套类型
| 类型 | 定义 |
result_type
|
std::uint_least32_t |
数据成员
| 成员 | 描述 |
std::
vector
<
result_type
>
v
|
底层种子序列
( 仅用于说明的成员对象* ) |
成员函数
构造并初始化
std::seed_seq
对象
(公开成员函数) |
|
|
operator=
[deleted]
|
std::seed_seq
不可赋值
(公开成员函数) |
|
计算消除偏差的均匀分布32位值
(公开成员函数) |
|
|
获取存储的32位值的数量
(公开成员函数) |
|
|
复制所有存储的32位值
(公开成员函数) |
示例
运行此代码
#include <cstdint> #include <iostream> #include <random> int main() { std::seed_seq seq{1, 2, 3, 4, 5}; std::vector<std::uint32_t> seeds(10); seq.generate(seeds.begin(), seeds.end()); for (std::uint32_t n : seeds) std::cout << n << '\n'; }
可能的输出:
4204997637 4246533866 1856049002 1129615051 690460811 1075771511 46783058 3904109078 1534123438 1495905678