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:
IntType-- indicates a signed or unsigned integral type
UIntType-- indicates an unsigned integral type
RealType-- indicates a floating point type
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:
result_type x0-- creates an engine seeded as if by calling
Seed_seq& seq-- creates an engine seeded as if by calling
Seed_seqis a seed sequence template parameter.
typedef numeric-type result_type-- the type returned by the generator's
result_type min()-- returns the minimum value returned by the generator's
result_type max()-- returns the maximum value returned by the generator's
result_typeis an integral type this is the maximum value that can actually be returned; when
result_typeis a floating point type this is the smallest value greater than all values that can be returned.
void seed()-- the seed function seeds the engine with default seed values.
void seed(result_type x0)-- the seed function seeds the engine with seed value
void seed(Seed_seq& seq)-- the seed function seeds the engine with seed values from
Seed_seqis a seed sequence template parameter.
template <class InIt> void seed(InIt& first, InIt last)-- the seed function seeds the engine with values of type
unsigned longfrom the half-open sequence pointed to by
[first, last). If the sequence is not long enough to fully initialize the engine the function stores the value
firstand throws an object of type
result_type operator()()-- returns values uniformly distributed between
void discard(unsigned long long count)-- effectively calls
counttimes and discards each value.
In addition, every engine has a state that determines
the sequence of values that will be generated by subsequent calls to
The states of two objects of the same type can be compared with
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
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.
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:
typedef numeric-type input_type[removed with C++11] -- the type that the engine passed to
typedef numeric-type result_type-- the type returned by the distribution's
void reset()-- discards any cached values, so that the result of the next call to
operator()will not depend on any values obtained from the engine prior to the call.
template <class Engine> result_type operator()(Engine& eng)-- returns values distributed in accordance with the distribution's definition, using
engas a source of uniformly distributed random values and the stored parameter package.
Beginning with C++11, every distribution also has:
typedef unspecified-type param_type-- the package of parameters passed to
operator()to generate its return value.
const param&constructor -- initializes the stored parameter package from its argument
param_type param() const-- gets the stored parameter package
void param(const param_type&)-- sets the stored parameter package from its argument
template <class Engine> result_type operator()(Engine& eng, param_type par0)-- returns values distributed in accordance with the distribution's definition, using
engas a source of uniformly distributed random values and the parameter package
A parameter package is an object that stores all the parameters needed for a distribution. It contains:
typedef distribution-type distribution_type-- the type of its distribution.
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:
typedef numeric-type result_type-- an unsigned integer type of at least 32 bits.
Seed_seq-- creates a default seed sequence.
Seed_seq(InIt begin, InIt end)-- creates a seed sequence initialized from the parameter sequence
Seed_seq(initializer_list<result_type> ilist)-- creates a seed sequence initialized from
void generate(RanIt begin, RanIt end)-- stores values into the iterator range
size_t size()-- returns the length of the parameter sequence.
void param(Seed_seq& dest)-- copies the parameter sequence to
is the prototypical example of a seed sequence.
See also the Table of Contents and the Index.
Copyright © 1992-2013 by Dinkumware, Ltd. All rights reserved.