std:: piecewise_linear_distribution
|
헤더에 정의됨
<random>
|
||
|
template
<
class
RealType
=
double
>
class piecewise_linear_distribution ; |
(C++11부터) | |
std::piecewise_linear_distribution
는 여러 하위 구간
[b
i
, b
i+1
)
각각에서 선형 확률 밀도 함수에 따라 분포된 임의의 부동 소수점 숫자를 생성합니다. 이 분포는 각 구간 경계에서의 확률 밀도가 미리 정의된 값
p
i
와 정확히 일치하도록 구성됩니다.
| b i+1 -x |
| b i+1 -b i |
| x-b i |
| b i+1 -b i |
| 1 |
| 2 |
구간 경계들의 집합 b i 과 경계에서의 가중치들의 집합 w i 는 이 분포의 매개변수들입니다.
std::piecewise_linear_distribution
는
RandomNumberDistribution
의 모든 요구 사항을 충족합니다.
목차 |
템플릿 매개변수
| RealType | - | 생성기에 의해 생성되는 결과 타입. 이것이 float , double , 또는 long double 중 하나가 아닌 경우의 효과는 정의되지 않습니다. |
멤버 타입
| 멤버 타입 | 정의 |
result_type
(C++11)
|
RealType |
param_type
(C++11)
|
매개변수 집합의 타입, RandomNumberDistribution 참조. |
멤버 함수
|
(C++11)
|
새로운 분포를 생성함
(public member function) |
|
(C++11)
|
분포의 내부 상태를 재설정함
(public member function) |
생성 |
|
|
(C++11)
|
분포에서 다음 난수를 생성함
(public member function) |
특성 |
|
|
(C++11)
|
분포 매개변수를 반환함
(public member function) |
|
(C++11)
|
분포 매개변수 객체를 가져오거나 설정함
(public member function) |
|
(C++11)
|
잠재적으로 생성될 수 있는 최소값을 반환함
(public member function) |
|
(C++11)
|
잠재적으로 생성될 수 있는 최대값을 반환함
(public member function) |
비멤버 함수
|
(C++11)
(C++11)
(C++20에서 제거됨)
|
두 분포 객체를 비교함
(함수) |
|
(C++11)
|
의사 난수 분포에 대한 스트림 입출력을 수행함
(함수 템플릿) |
예제
#include <iomanip> #include <iostream> #include <map> #include <random> #include <string> int main() { std::random_device rd; std::mt19937 gen{rd()}; // 0에서 5까지 확률 증가 // 5에서 10까지는 평평하게 유지 // 10에서 15까지는 동일한 비율로 감소 std::vector<double> i{0, 5, 10, 15}; std::vector<double> w{0, 1, 1, 0}; std::piecewise_linear_distribution<> d{i.begin(), i.end(), w.begin()}; std::map<int, int> hist; for (int n{}; n < 1e4; ++n) ++hist[d(gen)]; for (auto [x, y] : hist) std::cout << std::setw(2) << std::setfill('0') << x << ' ' << std::string(y / 100, '*') << '\n'; }
가능한 출력:
00 * 01 *** 02 **** 03 ****** 04 ********* 05 ********* 06 ********* 07 ********** 08 ********* 09 ********** 10 ********* 11 ******* 12 **** 13 *** 14 *