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:

-- indicates a signed or unsigned integral type`IntType`

-- indicates an unsigned integral type`UIntType`

-- indicates a floating point type`RealType`

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:

- a default constructor -- creates an engine seeded as if by calling
`seed()`

. - [added with C++11]
an explicit constructor with argument
`result_type x0`

-- creates an engine seeded as if by calling`seed(x0)`

. - [added with C++11]
an explicit constructor with argument
`Seed_seq& seq`

-- creates an engine seeded as if by calling`seed(seq)`

, where`Seed_seq`

is a seed sequence template parameter. `typedef`

-- the type returned by the generator's*numeric-type***result_type**`operator()`

.`result_type`

-- returns the minimum value returned by the generator's**min**()`operator()`

.`result_type`

-- returns the maximum value returned by the generator's**max**()`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`

-- the**seed**()**seed function**seeds the engine with default seed values.- [added with C++11]
`void`

-- the seed function seeds the engine with seed value**seed**(result_type x0)`x0`

. - [added with C++11]
`void`

-- the seed function seeds the engine with seed values from**seed**(Seed_seq& seq)`seq`

, where`Seed_seq`

is a seed sequence template parameter. - [TR1 engines only]
`template <class InIt> void`

-- the**seed**(InIt& first, InIt last)**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`

-- returns values uniformly distributed between**operator()**()`min()`

and`max()`

.- [added with C++11]
`void`

-- effectively calls**discard**(unsigned long long count)`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`

[removed with C++11] -- the type that the engine passed to*numeric-type***input_type**`operator()`

should return.`typedef`

-- the type returned by the distribution's*numeric-type***result_type**`operator()`

.`void`

-- discards any cached values, so that the result of the next call to**reset**()`operator()`

will not depend on any values obtained from the engine prior to the call.`template <class Engine> result_type`

-- returns values distributed in accordance with the distribution's definition, using**operator()**(Engine& eng)`eng`

as a source of uniformly distributed random values and the stored parameter package.

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

`typedef`

-- the package of parameters passed to*unspecified-type***param_type**`operator()`

to generate its return value.- A
`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`

-- returns values distributed in accordance with the distribution's definition, using**operator()**(Engine& eng, param_type par0)`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`

-- the type of its distribution.*distribution-type*distribution_type- One or more constructors that take the same parameter lists as for the distribution constructors.
- The same parameter-access functions as the distribution.
- Equality and inequality comparison operators.

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`

-- an unsigned integer type of at least 32 bits.*numeric-type***result_type**`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.*