std::mersenne_twister_engine::seed
void seed( result_type value = default_seed ); | (1) | (since C++11) |
---|---|---|
template< class Sseq > void seed( Sseq& seq ); | (2) | (since C++11) |
使用新的种子值重新初始化随机数引擎的内部状态。
参数
value | - | seed value to use in the initialization of the internal state |
---|---|---|
seq | - | seed sequence to use in the initialization of the internal state |
例外
%280%29
复杂性
例
二次
#include <iostream>
#include <random>
int main()
{
std::mt19937 gen;
// Seed the engine with an unsigned int
gen.seed(1);
std::cout << "after seed by 1: " << gen() << '\n';
// Seed the engine with two unsigned ints
std::seed_seq sseq{1, 2};
gen.seed(sseq);
std::cout << "after seed by {1,2}: " << gen() << '\n';
}
二次
可能的产出:
二次
after seed by 1: 1791095845
after seed by {1,2}: 3127717181
二次
© cppreference.com
在CreativeCommonsAttribution下授权-ShareAlike未移植许可v3.0。
本文档系腾讯云开发者社区成员共同维护,如有问题请联系 cloudcommunity@tencent.com