Random Sample
Generates random numbers following a negative binomial distribution.
Controller: CodeCogs
Dependents
Interface
C++
Class RandomSample
The negative binomial distribution, also known as the Pascal distribution or Plya distribution, gives the probability of successes and failures in trials, and success on the 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.
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::RandomSampleunknown( | double | NX | |
double | PX | ||
double | s | ) |
Source Code
Source code is available when you buy a Commercial licence.
Not a member, then Register with CodeCogs. Already a Member, then Login.