VOOZH about

URL: https://www.geeksforgeeks.org/cpp/negative_binomial_distribution-in-c-with-examples/

⇱ negative_binomial_distribution in C++ with Examples - GeeksforGeeks


  • Courses
  • Tutorials
  • Interview Prep

negative_binomial_distribution in C++ with Examples

Last Updated : 16 Dec, 2021

This function is defined in header randomRandom. Negative binomial distribution is Random number distribution that produces integers according to a negative binomial discrete distribution (also known as Pascal distribution), which is described by the following probability mass function. 

The value represents the number of failures in a series of independent yes/no trials (each succeeds with probability p), before exactly k successes occur. 
Syntax : 

template( class IntType = int )
class negative_binomial_distribution


Template Parameter : 
IntType : The result type generated by the generator.
Member Types 
Member type & Definition 
 

result_typeIntType
param_typeThe type returned by member param


Member functions : public member function 

  • constructor(): Construct negative binomial distribution
  • operator(): Generate random number
  • reset: Reset distribution
  • param: Distribution parameters
  • min : Minimum value
  • max : Maximum value


Distribution parameters : public member function 

  • k :Distribution parameter k 
  • p :Distribution parameter p


Non-member functions : Function Templates 

  • operator<< :Insert into output stream
  • operator>> :Extract from input stream 
  • relational operators : Relational operators


Below program to illustrate the above template 

Output : 

Negative binomial distribution with ( k = 4, p = 0.5 ) :
0: *****
1: ************
2: ****************
3: ***************
4: *************
5: **********
6: ********
7: *****
8: ***
9: **


Below program with distribution parameter of 1 and 20% 
Program 2: 

Output : 

Negative binomial distribution with ( k = 1, p = 0.2 ) :
0: *******************
1: ***************
2: ************
3: **********
4: ********
5: ******
6: *****
7: ****
8: ***
9: **
Comment
Article Tags:
Article Tags: