Rogue Wave banner
Previous fileTop of DocumentContentsIndex pageNext file
Essential Math Module User's Guide
Rogue Wave web site:  Home Page  |  Main Documentation Page

6.1 Random Number Generators

The Essential Math Module provides random number generators for a variety of probability distributions. Each of these generators has the ability to generate uniform random deviates in the range (0,1). Uniform deviates are random numbers that lie within a specified range, with any one number in the range just as likely as any other. The Essential Math Module random number generators first generate a random uniform deviate in the range (0,1), then from this deviate derive a random number from the appropriate probability distribution. Thus, the statistical properties and performance of the Essential Math Module random number generators depend on the statistical properties and performance of the underlying uniform deviate generator.

The algorithms that generate uniform random deviates vary widely. Some are very quick, but have poor statistical properties; others have excellent statistical properties, but are slow. If a random number generator is not giving good results in a particular instance, standard practice is to try another algorithm. For this reason, the random number generator classes supplied with the Essential Math Module are parameterized by uniform generator type using the C++ template mechanism. This lets you pick the algorithm to generate the underlying random deviates in the random number classes without having to modify source code or derive your own class.

The random number generator classes in the Essential Math Module all derive from the abstract base class RWTRand<Generator>. This base class contains and provides access to the uniform deviate generator Generator, and declares the function call operator as a pure virtual function that returns a double.

The following example illustrates the function call operator:

The template parameter to the random number classes must be a function object; that is, it must be a class that defines the function call operator to return a random deviate of type double in the range (0,1), or [0,1]. In addition, the class must possess a default constructor. The Essential Math Module provides the general purpose uniform (0,1) generator, RWRandGenerator, which may be used as the template parameter in all the random number classes. The SourcePro C++ API Reference Guide contains details on class RWRandGenerator. Section 9.10, "Random Number Generator Example," shows how to make a function object out of a function that computes a uniform random deviate. The random number generator classes are listed in Table 2.

Table 2: List of the random number generator classes, the include file that declares them, and the type of distribution that each returns

Class Include file Distribution
RWRandGenerator <rw/randgen.h> Uniform
RWRandGenMCG31M1 <rw/randmcg31m1.h> Uniform
RWRandGenMCG59 <rw/randmcg59.h> Uniform
RWRandGenMRG32K3A <rw/randmrg32k3a.h> Uniform
RWRandGenMTwist <rw/randmtwist.h> Uniform
RWRandGenR250 <rw/randr250.h> Uniform
RWTRandBinomial<T> <rw/rand.h> Binomial
RWTRandExponential<T> <rw/rand.h> Exponential
RWTRandGamma<T> <rw/rand.h> Gamma
RWTRandNormal<T> <rw/rand.h> Normal (Gaussian)
RWTRandPoisson<T> <rw/rand.h> Poisson
RWTRandUniform<T> <rw/rand.h> Uniform

Note that each class has a similar interface. The following example prints a vector of 10 uniformly distributed random deviates:



Previous fileTop of DocumentContentsNo linkNext file

Copyright © Rogue Wave Software, Inc. All Rights Reserved.

The Rogue Wave name and logo, and SourcePro, are registered trademarks of Rogue Wave Software. All other trademarks are the property of their respective owners.
Provide feedback to Rogue Wave about its documentation.