Namespaces
Variants

std:: linear_congruential_engine

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

class UIntType,
UIntType a,
UIntType c,
UIntType m

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

linear_congruential_engine 선형 합동 생성기 (LCG)에 기반한 난수 엔진입니다.

목차

템플릿 매개변수

UIntType - 생성기가 생성하는 결과 타입. 이 타입이 다음 중 하나가 아닌 경우의 효과는 정의되지 않음: unsigned short , unsigned int , unsigned long , 또는 unsigned long long .
a - 승수 항
c - 증분 항
m - 모듈러스 항

m 이 0이 아닐 때, a >= m 또는 c >= m true 인 경우, 프로그램은 형식이 잘못되었습니다.

생성기 속성

linear_congruential_engine 의 상태 크기 1 로, 각 상태는 단일 정수로 구성됩니다.

실제 모듈러스 m 0 는 다음과 같이 정의됩니다:

  • 만약 m 이 0이 아니면, m 0 m 입니다.
  • 만약 m 이 0이면, m 0 std:: numeric_limits < result_type > :: max ( ) 값에 1 을 더한 값입니다(이는 m 0 result_type 로 표현 가능할 필요가 없음을 의미합니다).

linear_congruential_engine 전이 알고리즘 TA(x i ) = (a·x i +c) mod m 0 입니다.

linear_congruential_engine 생성 알고리즘 GA(x i ) = (a·x i +c) mod m 0 입니다.

현재 상태로 생성된 의사 난수는 또한 후속 상태입니다.

미리 정의된 특수화

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

헤더 파일에 정의됨 <random>
타입 정의
minstd_rand0 (C++11) std :: linear_congruential_engine < std:: uint_fast32_t ,
16807 , 0 , 2147483647 >

1969년 Lewis, Goodman 및 Miller가 발견하고, 1988년 Park과 Miller에 의해 "최소 표준"으로 채택됨

minstd_rand (C++11)

std :: linear_congruential_engine < std:: uint_fast32_t ,
48271 , 0 , 2147483647 >
Park, Miller 및 Stockmeyer가 1993년에 권장한 새로운 "최소 표준"

중첩 타입

유형 정의
result_type UIntType

데이터 멤버

constexpr UIntType multiplier
[static]
a
(공개 정적 멤버 상수)
constexpr UIntType increment
[static]
c
(공개 정적 멤버 상수)
constexpr UIntType modulus
[static]
m
(공개 정적 멤버 상수)
constexpr UIntType default_seed
[static]
1u
(공개 정적 멤버 상수)

멤버 함수

생성 및 시드 설정
엔진을 생성함
(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) (C++20에서 제거됨)
두 의사 난수 엔진의 내부 상태를 비교함
(함수)
의사 난수 엔진에 대한 스트림 입출력을 수행함
(함수 템플릿)

예제