Random Number Generators


A random number generator is an object that produces a sequence of pseudo-random values. A generator that produces values uniformly distributed within a specified range is an engine. An engine can be combined with a distribution, either by passing the engine as an argument to the distribution's operator() or by using a variate_generator, to produce values that are distributed in a manner defined by the distribution.

Most of the random number generators are templates whose parameters customize the generator. The descriptions of generators that take a type as an argument use common template parameter names to describe some of the properties of the type permitted as an actual argument type:

Engines

An engine is a class or template class whose instances act as a source of random numbers uniformly distributed between a minimum and maximum value. An engine can be a simple engine or a compound engine. Every engine has the following members:

In addition, every engine has a state that determines the sequence of values that will be generated by subsequent calls to operator(). The states of two objects of the same type can be compared with operator== and operator!=; if the two states compare equal the objects will generate the same sequence of values. The state of an object can be saved to a stream as a sequence of 32-bit unsigned values with the object's operator<<; the state is not changed by saving it. A saved state can be read into an object of the same type with operator>>.

A simple engine is an engine that produces random numbers directly. This library provides one class whose objects are simple engines. It also provides four class templates which can be instantiated with values that provide parameters for the algorithm they implement, and nine predefined instances of those class templates. Objects of these types are also simple engines.

A compound engine is an engine that obtains random numbers from one or more simple engines and generates a stream of uniformly distributed random numbers from those values. The library provides class templates for two compound engines.

Distributions

A distribution is a class or template class whose instances transform a stream of uniformly distributed random numbers obtained from an engine into a stream of random numbers with a particular distribution. Every distribution has the following members:

Beginning with C++11, every distribution also has:

A parameter package is an object that stores all the parameters needed for a distribution. It contains:

Seed Sequences

A seed sequence is a C++11 class or template class whose instances supply the initial, or seed, sequence for initializing a generator. Every seed sequence of type Seed_seq has the following members:

Class seed_seq is the prototypical example of a seed sequence.

Checking Preconditions

The library can be built as a checked version and as an unchecked version. The checked version uses a macro similar to C's assert macro to test the conditions marked as Preconditions in the functional descriptions. To use the checked version, define either the macro _RNG_CHECK or the macro _DEBUG to a non-zero numeric value in all code that uses the library.


See also the Table of Contents and the Index.

Copyright © 1992-2013 by Dinkumware, Ltd. All rights reserved.