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 typeUIntType
-- indicates
an unsigned integral typeRealType
-- indicates
a floating point typeAn 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:
seed()
.result_type x0
--
creates an engine seeded as if by calling seed(x0)
.Seed_seq& seq
--
creates an engine seeded as if by calling seed(seq)
,
where Seed_seq
is a
seed sequence template parameter.typedef numeric-type result_type
-- the type returned by
the generator's operator()
.result_type min()
-- returns the minimum value returned by
the generator's operator()
.result_type max()
-- returns the maximum value returned by
the generator's operator()
. When result_type
is an integral type this is the maximum value that can actually be returned;
when result_type
is 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 x0
.void seed(Seed_seq& seq)
-- the seed function
seeds the engine with seed values from seq
,
where Seed_seq
is 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 long
from 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 last
in first
and throws an object of type invalid_argument
.result_type operator()()
-- returns values uniformly
distributed between min()
and max()
.void discard(unsigned long long count)
-- effectively calls
operator()
count
times 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 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.
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 operator()
should return.typedef numeric-type result_type
-- the type
returned by the distribution's operator()
.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
eng
as 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 argumentparam_type param() const
-- gets the
stored parameter packagevoid param(const param_type&)
-- sets the
stored parameter package from its argumenttemplate <class Engine> result_type operator()(Engine& eng, param_type par0)
--
returns values distributed in accordance with the distribution's definition, using
eng
as a source of uniformly distributed random values
and the parameter package par0
.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 [begin, end)
.Seed_seq(initializer_list<result_type> ilist)
--
creates a seed sequence initialized from ilist
.void generate(RanIt begin, RanIt end)
-- stores values into
the iterator range [begin, end)
.size_t size()
-- returns the length of the parameter sequence.void param(Seed_seq& dest)
-- copies the parameter sequence
to dest
Class seed_seq
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.