9.1: Overview |
These are the basic random number generators (RNGs):
To use these generators, you need to include
some subset of these headers:
#include <random/uniform.h>
#include <random/normal.h>
#include <random/exponential.h>
#include <random/discrete-uniform.h>
#include <random/beta.h>
#include <random/gamma.h>
#include <random/chisquare.h>
#include <random/F.h>
using namespace ranlib;
9.2: Note: Parallel random number generators |
The generators which Blitz++ provides are not suitable for parallel programs. If you need parallel RNGs, you may find SPRNG useful.
9.3: Seeding a random number generator |
9.4: Detailed description of RNGs |
There are really two types of RNGs:
By default, the Integer RNG used is a faithful adaptation of
the Mersenne Twister MT19937 due to
Matsumoto and Nishimura (see ACM Transactions on Modeling
and Computer Simulation, Vol. 8, No. 1, January 1998, pp 3-30,
web page,
paper).
This generator has a period of 219937-1
, passed several stringent statistical
tests (including the Diehard tests), and
has speed comparable to other modern generators.
9.5: Template parameters |
RNGs take three template parameters, all of which have default
values. Using the Uniform
RNG as an example, the template
parameters of Uniform<T, IRNG, stateTag>
are:
float
.
sharedState
or independentState
.
If sharedState
, the IRNG is shared with other generators.
If independentState
, the RNG contains its own IRNG. The
default is sharedState.
9.6: Member functions |
RNGs have these methods:
T random();
Returns a random number.
void seed(unsigned int);
Seeds the underlying IRNG. See above for an example of seeding
with the system timer.
9.7: Detailed listing of RNGs |
9.7.1: random/uniform.h |
Uniform<>()
Continuous uniform distribution on [0,1).
UniformClosedOpen<>()
Continuous uniform distribution on [0,1). Same as Uniform<>
.
UniformClosed<>()
Continuous uniform distribution on [0,1].
UniformOpen<>()
Continuous uniform distribution on (0,1).
UniformOpenClosed<>()
Continuous uniform distribution on (0,1].
9.7.2: random/normal.h |
NormalUnit<>()
Continuous normal distribution with mean 0 and variance 1.
Normal<>(T mean, T standardDeviation)
Continuous normal distribution with specified mean and standard
deviation.
9.7.3: random/exponential.h |
ExponentialUnit<>()
Continuous exponential distribution with mean 1.
Exponential<>(T mean)
Continuous exponential distribution with specified mean.
9.7.4: random/beta.h |
Beta<>(T a, T b)
Beta distribution with parameters a and b. The mean of the distribution
is a/(a+b) and its variance
is ab/((a+b)^2(a+b+1)).
Use the method setParameters(T a, T b)
to change the
parameters.
9.7.5: random/chisquare.h |
ChiSquare<>(T df)Chi Square distribution with df degrees of freedom. The parameter df must be positive. Use the method
setDF(T df)
to change the degrees of freedom.
9.7.6: random/gamma.h |
Gamma<>(T mean)
Gamma distribution with specified mean. The mean must
be positive. Use the method setMean(T mean)
to
change the mean.
9.7.7: random/F.h |
F<>(T numeratorDF, T denominatorDF)F distribution with numerator and denominator degrees of freedom specified. Both these parameters must be positive. Use
setDF(T dfn, T dfd)
to change the
degrees of freedom.
9.7.8: random/discrete-uniform.h |
DiscreteUniform<>(T n)
Discrete uniform distribution over 0, 1, ..., n-1.