std:: discrete_distribution
|
헤더에 정의됨
<random>
|
||
|
template
<
class
IntType
=
int
>
class discrete_distribution ; |
(C++11부터) | |
std::discrete_distribution
는 구간
[
0
,
n
)
에서 임의의 정수를 생성하며, 각 개별 정수
i
의 확률은
w
i
/S
로 정의됩니다. 즉,
i
번째 정수의
가중치
를 모든
n
개 가중치의 합으로 나눈 값입니다.
std::discrete_distribution
는
RandomNumberDistribution
의 모든 요구 사항을 충족합니다.
목차 |
템플릿 매개변수
| IntType | - | 생성자가 생성하는 결과 타입. 이것이 다음 중 하나가 아닌 경우의 효과는 정의되지 않음: short , int , long , long long , unsigned short , unsigned int , unsigned long , 또는 unsigned long long . |
멤버 타입
| 멤버 타입 | 정의 |
result_type
(C++11)
|
IntType |
param_type
(C++11)
|
매개변수 집합의 타입, RandomNumberDistribution 참조. |
멤버 함수
|
(C++11)
|
새로운 분포를 생성함
(public member function) |
|
(C++11)
|
분포의 내부 상태를 재설정함
(public member function) |
생성 |
|
|
(C++11)
|
분포에서 다음 난수를 생성함
(public member function) |
특성 |
|
|
확률 목록을 얻음
(public member function) |
|
|
(C++11)
|
분포 매개변수 객체를 얻거나 설정함
(public member function) |
|
(C++11)
|
잠재적으로 생성될 수 있는 최소값을 반환함
(public member function) |
|
(C++11)
|
잠재적으로 생성될 수 있는 최대값을 반환함
(public member function) |
비멤버 함수
|
(C++11)
(C++11)
(removed in C++20)
|
두 분포 객체를 비교함
(함수) |
|
(C++11)
|
의사 난수 분포에 대한 스트림 입출력을 수행함
(함수 템플릿) |
예제
#include <iomanip> #include <iostream> #include <map> #include <random> int main() { std::random_device rd; std::mt19937 gen(rd()); std::discrete_distribution<> d({40, 10, 10, 40}); std::map<int, int> map; for (int n = 0; n < 1e4; ++n) ++map[d(gen)]; for (const auto& [num, count] : map) std::cout << num << " generated " << std::setw(4) << count << " times\n"; }
가능한 출력:
0 generated 4037 times 1 generated 962 times 2 generated 1030 times 3 generated 3971 times