Database Reference
In-Depth Information
Implementations of the Mersenne Twister algorithm exist for many
languagesandareincludedinmanylibraries, includingtheColtlibraryused
in this chapter.
The Mersenne Twister object is initialized in the usual way and can provide
random draws (also called random variates) in a variety of forms, especially
the integer and double forms that are used extensively throughout the
remainder of this chapter.
Generating Specific Distributions
A basic random number generator is designed to draw from a uniform
distribution. If draws (also called variates ) are needed, the uniform variate,
or a combination of uniform variates, is transformed into the appropriate
distribution. This section introduces some of the simpler methods of
drawing from these distributions in case appropriate libraries are not
available. If libraries are available, they are usually preferred because they
often implement more complicated, but faster, methods of drawing random
variates. In particular, they often implement the ziggurat algorithm , one of
the fastest methods for drawing random variables.
In any case, the simple methods are all based on a good uniform random
number generator, such as the Mersenne Twister discussed in the previous
section:
import cern.jet.random.engine.MersenneTwister;
public class Distribution {
MersenneTwister rng = new MersenneTwister();
Exponential and Poisson Random Numbers
When the CDF of the distribution has an invertible closed form, drawing a
random number from the distribution is very easy. Because a CDF is always
between 0 and 1, inclusive, a uniform random number in [0,1] is drawn and
then plugged into the inverse of CDF to find the value of x.
This is the case when drawing values from the exponential distribution.
Recalling the probability density function from earlier in the chapter, the
cumulative density function for the exponential is simply u=1-e -px .
Some simple manipulation to solve for x given u, yields x = -log(1-u)/p.
Because u is a uniform random number, 1-u can simply be replaced with
Search WWH ::




Custom Search