mersenne_twister::seed
엔진을 시드합니다.
template<class Gen>
void seed(Gen& gen)
void seed(unsigned long x0 = default_seed);
매개 변수
Gen
시드 생성자의 형식입니다.gen
시드 생성기입니다.x0
시드 값입니다.
설명
전제 조건:0 < x0
첫 번째 시드 함수 생성 N 값 형식의 값 unsigned long 의 후속 호출에 의해 반환 된 gen 및 결과 큰 정수 값을 이미지가 자유롭게 비틀리 고.각 값이 gen() % 2W.
가장 오래 된 기록 값을 설정 하는 두 번째 시드 함수 h[0] 에 x0 mod 2W, 다음 각 연속 기록 값을 반복적으로 설정 h[i] 에 (i + 1812433253 * (h[i - 1] >> (W - 2))) mod 2W에 대 한 i 이르는 1 에 N - 1.
예제
// std_tr1__random__mersenne_twister_seed.cpp
// compile with: /EHsc
#include <random>
#include <iostream>
typedef std::minstd_rand Myeng;
typedef std::mersenne_twister<unsigned int, 32, 624,
397, 31, 0x9908b0df, 11, 7, 0x9d2c5680,
15, 0xefc60000, 18> Myceng; // same as mt19937
int main()
{
Myeng eng;
Myceng ceng;
Myceng::result_type compval = ceng();
compval = compval; // to quiet "unused" warnings
std::cout << "W == " << Myceng::word_size << std::endl;
std::cout << "N == " << Myceng::state_size << std::endl;
std::cout << "M == " << Myceng::shift_size << std::endl;
std::cout << "R == " << Myceng::mask_bits << std::endl;
std::cout << "A == " << Myceng::parameter_a << std::endl;
std::cout << "U == " << Myceng::output_u << std::endl;
std::cout << "S == " << Myceng::output_s << std::endl;
std::cout << "B == " << Myceng::output_b << std::endl;
std::cout << "T == " << Myceng::output_t << std::endl;
std::cout << "C == " << Myceng::output_c << std::endl;
std::cout << "L == " << Myceng::output_l << std::endl;
std::cout << "min == " << ceng.min() << std::endl;
std::cout << "max == " << ceng.max() << std::endl;
ceng.seed(); // reseed base engine
std::cout << "a random value == " << ceng() << std::endl;
std::cout << "a random value == " << ceng() << std::endl;
std::cout << "a random value == " << ceng() << std::endl;
Myceng ceng2(eng); // construct with generator
ceng2.seed(eng); // seed with generator
Myceng ceng3(5UL); // construct with unsigned long seed
ceng3.seed(5UL); // seed with unsigned long
return (0);
}
요구 사항
헤더: <random>
네임 스페이스: std