Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
negative_binomial_distribution in C++ with Examples
In this tutorial, we will be discussing a program to understand negative_binomial_distribution in C++.
This function follows the negative Binomial discrete distribution and produces integers according to this random distribution.
Example
#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;
}
Output
Negative binomial distribution with ( k = 4, p = 0.5 ) : 0: ***** 1: ************ 2: **************** 3: *************** 4: ************* 5: ********** 6: ******** 7: ***** 8: *** 9: **
Advertisements