이 튜토리얼에서는 C++에서 negative_binomial_distribution을 이해하는 프로그램에 대해 논의할 것입니다.
이 함수는 음의 이항 이산 분포를 따르고 이 무작위 분포에 따라 정수를 생성합니다.
예시
#include <bits/stdc++.h>
using namespace std;
int main() {
//setting number of experiments
const int exps = 10000;
const int numberstars = 100;
default_random_engine generator;
negative_binomial_distribution<int> distribution(4, 0.5);
int p[10] = {};
for (int i = 0; i < exps; ++i) {
int counting = distribution(generator);
if (counting < 10)
++p[counting];
}
cout << "Negative binomial distribution with "<< "( k = 4, p = 0.5 ) :" << endl;
//printing the sequence from the array
for (int i = 0; i < 10; ++i)
cout << i << ": " << string(p[i] * numberstars / exps, '*') << endl;
return 0;
} 출력
Negative binomial distribution with ( k = 4, p = 0.5 ) : 0: ***** 1: ************ 2: **************** 3: *************** 4: ************* 5: ********** 6: ******** 7: ***** 8: *** 9: **