std::seed_seq
STD:种子[医]SEQ
Defined in header | | |
---|---|---|
class seed_seq; | | (since C++11) |
std::seed_seq使用整数值数据序列,并生成所请求的无符号整数值数。i,0≤i<232
,基于消耗的数据。所产生的值分布在整个32位范围内,即使消耗的值接近。
它提供了一种方法来为大量的随机数引擎播种种子,或者在给定一个小种子或一个分布不佳的初始种子序列的情况下,为需要大量熵的生成器播种。
std::seed_seq
满足…的要求SeedSequence
...
成员类型
Member type | Definition |
---|---|
result_type | std::uint_least32_t |
成员函数
(constructor) | constructs and seeds the std::seed_seq object (public member function) |
---|---|
operator= (deleted) | not copy-assignable (public member function) |
generate | calculates the bias-eliminated, evenly distributed 32-bit values (public member function) |
size | obtains the number of 32-bit values stored in std::seed_seq (public member function) |
param | obtains the 32-bit values stored in std::seed_seq (public member function) |
例
二次
#include <random>
#include <cstdint>
#include <iostream>
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
二次
© cppreference.com
在CreativeCommonsAttribution下授权-ShareAlike未移植许可v3.0。