Namespaces
Variants

std:: mersenne_twister_engine

From cppreference.net
헤더 파일에 정의됨 <random>
template <

class UIntType, std:: size_t w, std:: size_t n, std:: size_t m, std:: size_t r,
UIntType a, std:: size_t u, UIntType d, std:: size_t s,
UIntType b, std:: size_t t, UIntType c, std:: size_t l, UIntType f

> class mersenne_twister_engine ;
(C++11부터)

mersenne_twister_engine 메르센 트위스터 알고리즘에 기반한 난수 엔진입니다. 이는 암호학적으로 안전하지는 않지만 고품질의 UIntType 타입 부호 없는 정수 난수를 [0, 2 w
)
구간에서 생성합니다.

목차

템플릿 매개변수

UIntType - 생성기가 생성하는 결과 타입. 이것이 다음 중 하나가 아닌 경우의 효과는 정의되지 않음: unsigned short , unsigned int , unsigned long , 또는 unsigned long long .
w - 엔진이 생성하는 값의 범위를 결정하는 2의 거듭제곱
n - 점화식의 차수
m - 중간 워드, 상태를 정의하는 점화식에서 사용되는 오프셋
r - 하위 비트 마스크의 비트 수, 트위스트 값이라고도 함
a - 조건부 XOR 마스크, 즉 유리 표준형 트위스트 행렬의 계수
u, d, s, b, t, c, l - 비트 스크램블링(템퍼링) 행렬의 1 부터 7 까지의 구성 요소
f - 초기화 승수

다음 제한 사항 중 하나라도 위반되면 프로그램은 잘못된 형식입니다:

  • m [ 1 , n ] 범위 내에 있습니다.
  • 다음 표현식들은 모두 true 입니다:
  • 주어진 ( 1u << w ) - 1u w1 로 할 때, 다음 표현식들은 모두 true 입니다:
  • a <= w1
  • b <= w1
  • c <= w1
  • d <= w1
  • f <= w1
**참고:** 제공된 텍스트는 모두 C++ 코드 조각으로 구성되어 있으며, 지시사항에 따라 ` ` 태그 내의 내용은 번역하지 않았습니다. HTML 구조와 코드는 원본 그대로 유지되었습니다.

생성기 속성

mersenne_twister_engine 의 상태 크기는 size n 이며, 각 상태는 result_type 타입의 n 개 값으로 구성된 시퀀스 X 로 이루어집니다. X j X j mod n 번째 값(0부터 시작)을 나타냅니다.

다음 비트 연산 표기법이 주어졌을 때:

mersenne_twister_engine 전이 알고리즘 ( TA(x i ) )은 다음과 같이 정의됩니다:

  1. X i-n 의 상위 w - r 비트와 X i+1-n 의 하위 r 비트를 연결하여 부호 없는 정수 값 Y 를 얻습니다.
  2. y a·(Y bitand 1) 로 설정하고, X i X i+m−n xor (Y rshift 1) xor y 으로 설정합니다.

mersenne_twister_engine 생성 알고리즘 ( GA(x i ) )은 다음과 같이 정의됩니다:

  1. z 1 X i xor ((X i rshift u) bitand d) 로 정의합니다.
  2. z 2 X i xor (((X i lshift s) mod 2 w
    ) bitand b)
    로 정의합니다.
  3. z 3 X i xor (((X i lshift t) mod 2 w
    ) bitand c)
    로 정의합니다.
  4. z 4 z 3 xor (z 3 rshift l) 로 정의합니다.
  5. z 4 를 결과로 반환합니다 (즉, GA(x i )=z 4 ).

미리 정의된 특수화

다음 특수화들은 일반적으로 사용되는 두 가지 매개변수 집합을 가진 난수 엔진을 정의합니다:

헤더에 정의됨 <random>
타입 정의
mt19937 (C++11)

std :: mersenne_twister_engine < std:: uint_fast32_t ,
32 , 624 , 397 , 31 ,
0x9908b0df , 11 ,
0xffffffff , 7 ,
0x9d2c5680 , 15 ,
0xefc60000 , 18 , 1812433253 >
Matsumoto와 Nishimura의 32비트 메르센 트위스터, 1998

mt19937_64 (C++11)

std :: mersenne_twister_engine < std:: uint_fast64_t ,
64 , 312 , 156 , 31 ,
0xb5026f5aa96619e9 , 29 ,
0x5555555555555555 , 17 ,
0x71d67fffeda60000 , 37 ,
0xfff7eee000000000 , 43 ,
6364136223846793005 >
Matsumoto와 Nishimura의 64비트 메르센 트위스터, 2000

중첩 타입

유형 정의
result_type UIntType

데이터 멤버

constexpr size_t word_size
[static]
w
(public static member constant)
constexpr size_t state_size
[static]
n
(public static member constant)
constexpr size_t shift_size
[static]
m
(public static member constant)
constexpr size_t mask_bits
[static]
r
(public static member constant)
constexpr UIntType xor_mask
[static]
a
(public static member constant)
constexpr size_t tempering_u
[static]
u
(public static member constant)
constexpr UIntType tempering_d
[static]
d
(public static member constant)
constexpr size_t tempering_s
[static]
s
(public static member constant)
constexpr UIntType tempering_b
[static]
b
(public static member constant)
constexpr size_t tempering_t
[static]
t
(public static member constant)
constexpr UIntType tempering_c
[static]
c
(public static member constant)
constexpr size_t tempering_l
[static]
l
(public static member constant)
constexpr UIntType initialization_multiplier
[static]
f
(public static member constant)
constexpr UIntType default_seed
[static]
5489u
(public static member constant)

멤버 함수

생성 및 시드 설정
엔진을 생성함
(public member function)
엔진의 현재 상태를 설정함
(public member function)
생성
엔진의 상태를 진행시키고 생성된 값을 반환함
(public member function)
지정된 양만큼 엔진의 상태를 진행시킴
(public member function)
특성
[static]
출력 범위에서 가능한 가장 작은 값을 얻음
(public static member function)
[static]
출력 범위에서 가능한 가장 큰 값을 얻음
(public static member function)

비멤버 함수

(C++11) (C++11) (removed in C++20)
두 의사 난수 엔진의 내부 상태를 비교함
(함수)
의사 난수 엔진에 대한 스트림 입출력을 수행함
(함수 템플릿)

예제