इस ट्यूटोरियल में, हम C++ में negative_binomial_distribution को समझने के लिए एक प्रोग्राम पर चर्चा करेंगे।
यह फंक्शन नकारात्मक द्विपद असतत वितरण का पालन करता है और इस यादृच्छिक वितरण के अनुसार पूर्णांक उत्पन्न करता है।
उदाहरण
#include <bits/stdc++.h>
using namespace std;
int main() {
// प्रयोगों की संख्या सेट करना
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;
// ऐरे से अनुक्रम प्रिंट करना
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: **