I have forgotten
my Password

Or login with:

  • Facebookhttp://facebook.com/
  • Googlehttps://www.google.com/accounts/o8/id
  • Yahoohttps://me.yahoo.com
this unit 4.99
sub units 5.10

Random Sample

Generates random numbers following a negative binomial distribution.
Controller: CodeCogs





Class RandomSample

The negative binomial distribution, also known as the Pascal distribution or Plya distribution, gives the probability of r - 1 successes and x failures in x + r - 1 trials, and success on the (x + r) th trial. The probability density function is therefore given by

The distribution function is then given by :

Using this class, the diagram below is generated from two distinct sequences of 1000 random numbers. Each pair of numbers are plotted against each other, to illustrate the negative binomial behaviour of this non-uniform random number generator.

12 10 12 13 12 7 7 7 7 13 7 7 11 3 11 12 15 7 8 10


The average running time for generating 100,000,000 random numbers using this class on a 750MHz microprocessor is 72 seconds.


  • MathWorld, http://mathworld.wolfram.com/NegativeBinomialDistribution.html

Example 1

#include <iostream>
#include <time.h>
#include <codecogs/stats/dists/discrete/negativebinomial/randomsample.h>
using namespace std;
int main() 
    Stats::Dists::Discrete::NegativeBinomial::RandomSample A(100, 0.1, 0.275);
    Stats::Dists::Discrete::NegativeBinomial::RandomSample B(114, 0.7, time(0) / MERSENNEDIV);
        cout << A.genReal() << " ";
    cout << endl;
        cout << B.genReal() << " ";
    cout << endl;
    return 0;


Lucian Bentea
Source Code

Source code is available when you buy a Commercial licence.



doubles )
Source Code

Source code is available when you buy a Commercial licence.
