I have forgotten
my Password

Or login with:

  • Facebookhttp://facebook.com/
  • Googlehttps://www.google.com/accounts/o8/id
  • Yahoohttps://me.yahoo.com
COST (GBP)
this unit 4.99
sub units 5.10
+
0

Random Sample

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

Dependents

Info

Interface

C++

Class RandomSample

The negative binomial distribution, also known as the Pascal distribution or Plya distribution, gives the probability of \inline  r - 1 successes and \inline  x failures in \inline  x + r - 1 trials, and success on the \inline  (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.

MISSING IMAGE!

1/negbinom-378.png cannot be found in /users/1/negbinom-378.png. Please contact the submission author.

Below you will find 20 numbers corresponding to the output of the first generator :
12 10 12 13 12 7 7 7 7 13 7 7 11 3 11 12 15 7 8 10

Speed:

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

References:

  • MathWorld, http://mathworld.wolfram.com/NegativeBinomialDistribution.html
  • The Newran03 random number generator library of Robert Davies, http://www.robertnz.net/nr03doc.htm

Example 1

The following example displays 40 random floating point numbers from a negative binomial distribution. It uses two different generators to achieve this. The first generator uses a particular value to initialize the seed, while the second one is using the system timer. Notice that it was necessary to divide the timer with the MERSENNEDIV value in order to keep the seed in the (0, 1) interval. Since the seed of the first generator is never changed, the first 20 numbers will always remain the same. However since the second generator is initialized via the system timer, the next 20 numbers will obviously vary with each execution of the program,
#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);
 
    for (int i = 0; i < 20; ++i)
        cout << A.genReal() << " ";
    cout << endl;
 
    for (int i = 0; i < 20; ++i)
        cout << B.genReal() << " ";
    cout << endl;
    return 0;
}

Authors

Lucian Bentea
Source Code

Source code is available when you buy a Commercial licence.

Not a member, then Register with CodeCogs. Already a Member, then Login.


Unknown

 
RandomSample::RandomSampleunknowndoubleNX
doublePX
doubles )
Constructor that sets up the class variables and initializes the associated random number generator with the given seed.
Source Code

Source code is available when you buy a Commercial licence.

Not a member, then Register with CodeCogs. Already a Member, then Login.