where is the <em>location parameter</em> and is the <em>scale parameter</em>.
The case where and is called the standard normal distribution.
Therefore the density of this particular distribution, which we also use with this random number generator is
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 standard normal
behaviour of this non-uniform random number generator.
Speed:
The average running time for generating 100,000,000 random numbers using this class
on a 750MHz microprocessor is 37 seconds.
References:
NIST/SEMATECH e-Handbook of Statistical Methods, http://www.itl.nist.gov/div898/handbook/
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 standard normal 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/statistics/distributions/continuous/normal/randomsample.h>usingnamespace std;
int main(){
Stats::Dists::Continuous::Normal::RandomSample A(0.335);
Stats::Dists::Continuous::Normal::RandomSample B(time(0) / MERSENNEDIV);
for(int i = 0; i < 20; ++i)cout << A.genReal() << endl;
cout << endl;
for(int i = 0; i < 20; ++i)cout << B.genReal() << endl;
return0;
}
Below you will find 20 numbers corresponding to the output of the first generator :
This function is a simple wrapper around the randomsample class provided in this module. It uses a static to keep a single instance of this class, so that each call to this function returns a new random number. As a result this function is not necessarily thread safe, in the sense that with identical initial seed, the sequence of random numbers may differ on a multitasking or multi threaded system.
The seed is only set on the first call to this function. Thereafter this parameter is ignored. If you do no want to set the seed, then we suggest you use the system clock the first time you call this function, i.e.