Throughout [rand],
the effect of instantiating a template:

- that has a template type parameter named Sseq is undefined unless the corresponding template argument is cv-unqualified and meets the requirements of seed sequence.
- that has a template type parameter named URBG is undefined unless the corresponding template argument is cv-unqualified and meets the requirements of uniform random bit generator.
- that has a template type parameter named Engine is undefined unless the corresponding template argument is cv-unqualified and meets the requirements of random number engine.
- that has a template type parameter named RealType is undefined unless the corresponding template argument is cv-unqualified and is one of float, double, or long double.
- that has a template type parameter named IntType is undefined unless the corresponding template argument is cv-unqualified and is one of short, int, long, long long, unsigned short, unsigned int, unsigned long, or unsigned long long.
- that has a template type parameter named UIntType is undefined unless the corresponding template argument is cv-unqualified and is one of unsigned short, unsigned int, unsigned long, or unsigned long long.

A *seed sequence*
is an object
that consumes a sequence
of integer-valued data
and produces a requested number
of unsigned integer values i, ,
based on the consumed data.

A class S
meets the requirements
of a seed sequence
if the expressions shown
in Table 121
are valid and have the indicated semantics,
and if S also meets all other requirements
of [rand.req.seedseq].

In Table 121 and throughout this subclause:

- T is the type named by S's associated result_type;
- q is a value of type S and r is a value of type S or const S;
- ib and ie are input iterators with an unsigned integer value_type of at least 32 bits;
- rb and re are mutable random access iterators with an unsigned integer value_type of at least 32 bits;
- ob is an output iterator; and
- il is a value of type initializer_list<T>.

Table 121: Seed sequence requirements [tab:rand.req.seedseq]

Expression | Return type | Pre/post-condition | Complexity | |

S::result_type | T | compile-time | ||

S() | Creates a seed sequence
with the same initial state as all other default-constructed seed sequences
of type S. | constant | ||

S(ib,ie) | Creates a seed sequence
having internal state
that depends on some or all of the bits
of the supplied sequence [ib,ie). | |||

S(il) | Same as S(il.begin(), il.end()). | same as S(il.begin(), il.end()) | ||

q.generate(rb,re) | void | |||

r.size() | size_t | The number of 32-bit units
that would be copied
by a call to r.param. | constant | |

r.param(ob) | void | Copies to the given destination
a sequence of 32-bit units
that can be provided
to the constructor of a second object of type S,
and that would reproduce in that second object
a state indistinguishable
from the state of the first object. |

A *uniform random bit generator*
g of type G
is a function object
returning unsigned integer values
such that each value
in the range of possible results
has (ideally) equal probability
of being returned.

template<class G>
concept uniform_random_bit_generator =
invocable<G&> && unsigned_integral<invoke_result_t<G&>> &&
requires {
{ G::min() } -> same_as<invoke_result_t<G&>>;
{ G::max() } -> same_as<invoke_result_t<G&>>;
requires bool_constant<(G::min() < G::max())>::value;
};

A class G meets the *uniform random bit generator* requirements if
G models uniform_random_bit_generator,
invoke_result_t<G&> is an unsigned integer type ([basic.fundamental]),
and
G provides a nested *typedef-name* result_type
that denotes the same type as invoke_result_t<G&>.

A *random number engine*
(commonly shortened to *engine*)
e of type E
is a uniform random bit generator
that additionally meets the requirements
(e.g., for seeding and for input/output)
specified in this subclause.

E's specification shall define:

- the size of E's state in multiples of the size of result_type, given as an integral constant expression;
- the
*transition algorithm*TA by which e's state e is advanced to its*successor state*e; and - the
*generation algorithm*GA by which an engine's state is mapped to a value of type result_type.

A class E
that meets the requirements
of a uniform random bit generator
also meets the requirements
of a *random number engine*
if the expressions shown
in Table 122
are valid and have the indicated semantics,
and if E also meets all other requirements
of [rand.req.eng].

In Table 122 and throughout this subclause:

- T is the type named by E's associated result_type;
- e is a value of E, v is an lvalue of E, x and y are (possibly const) values of E;
- s is a value of T;
- q is an lvalue meeting the requirements of a seed sequence;
- z is a value of type unsigned long long;
- os is an lvalue of the type of some class template specialization basic_ostream<charT, traits>; and
- is is an lvalue of the type of some class template specialization basic_istream<charT, traits>;

Table 122: Random number engine requirements [tab:rand.req.eng]

Expression | Return type | Pre/post-condition | Complexity | |

E() | Creates an engine
with the same initial state
as all other default-constructed engines
of type E. | |||

E(x) | Creates an engine
that compares equal to x. | |||

E(s) | Creates an engine
with initial state determined by s. | |||

E(q)246 | Creates an engine
with an initial state
that depends on a sequence
produced by one call
to q.generate. | same as complexity of q.generate
called on a sequence
whose length is size of state | ||

e.seed() | void | same as E() | ||

e.seed(s) | void | same as E(s) | ||

e.seed(q) | void | same as E(q) | ||

e() | T | per [rand.req.urng] | ||

e.discard(z)247 | void | no worse than the complexity
of z consecutive calls e() | ||

x == y | bool | |||

x != y | bool | !(x == y). | ||

os << x | reference to the type of os | With os. fmtflags set to
ios_base::dec|ios_base::left
and the fill character set to the space character,
writes to os
the textual representation
of x's current state.In the output,
adjacent numbers are separated
by one or more space characters. | ||

is >> v | reference to the type of is | With is.fmtflags
set to ios_base::dec,
sets v's state
as determined by reading its textual representation from is. If bad input is encountered,
ensures that v's state is unchanged by the operation
and
calls is.setstate(ios_base::failbit)
(which may throw ios_base::failure ([iostate.flags])). If a textual representation written via os << x
was subsequently read via is >> v,
then x == v
provided that there have been no intervening invocations
of x or of v. Preconditions: is provides a textual representation
that was previously written
using an output stream
whose imbued locale
was the same as that of is,
and whose type's template specialization arguments
charT and traits
were respectively the same as those of is. |

These operations shall each be of complexity
no worse than .

A *random number engine adaptor*
(commonly shortened to *adaptor*)
a of type A
is a random number engine
that takes values
produced by some other random number engine,
and applies an algorithm to those values
in order to deliver a sequence of values
with different randomness properties.

The requirements of a random number engine type
shall be interpreted as follows
with respect to a random number engine adaptor type.

```
A::A();
```

```
bool operator==(const A& a1, const A& a2);
```

```
A::A(result_type s);
```

```
template<class Sseq> A::A(Sseq& q);
```

```
void seed();
```

```
void seed(result_type s);
```

```
template<class Sseq> void seed(Sseq& q);
```

A shall also meet
the following additional requirements:

- The complexity of each function shall not exceed the complexity of the corresponding function applied to the base engine.
- Copying A's state (e.g., during copy construction or copy assignment) shall include copying the state of the base engine of A.
- The textual representation of A shall include the textual representation of its base engine.

A *random number distribution*
(commonly shortened to *distribution*)
d of type D
is a function object
returning values
that are distributed according to
an associated mathematical *probability density function*
p(z)
or according to
an associated *discrete probability function*
.

An associated probability function is typically expressed
using certain externally-supplied quantities
known as the *parameters of the distribution*.

Such distribution parameters are identified
in this context by writing, for example,
p(z | a,b) or ,
to name specific parameters,
or by writing, for example,
p(z |{p})
or ,
to denote a distribution's parameters p taken as a whole.

A class D
meets the requirements
of a *random number distribution*
if the expressions shown
in Table 123
are valid and have the indicated semantics,
and if D and its associated types
also meet all other requirements
of [rand.req.dist].

In Table 123 and throughout this subclause,

- T is the type named by D's associated result_type;
- P is the type named by D's associated param_type;
- d is a value of D, and x and y are (possibly const) values of D;
- glb and lub are values of T respectively corresponding to the greatest lower bound and the least upper bound on the values potentially returned by d's operator(), as determined by the current values of d's parameters;
- p is a (possibly const) value of P;
- g, g1, and g2 are lvalues of a type meeting the requirements of a uniform random bit generator;
- os is an lvalue of the type of some class template specialization basic_ostream<charT, traits>; and
- is is an lvalue of the type of some class template specialization basic_istream<charT, traits>;

Table 123: Random number distribution requirements [tab:rand.req.dist]

Expression | Return type | Pre/post-condition | Complexity | |

D::result_type | T | compile-time | ||

D::param_type | P | compile-time | ||

D() | Creates a distribution whose behavior is indistinguishable
from that of any other newly default-constructed distribution
of type D. | constant | ||

D(p) | Creates a distribution whose behavior is indistinguishable
from that of a distribution
newly constructed directly from the values used to construct p. | same as p's construction | ||

d.reset() | void | constant | ||

x.param() | P | no worse than the complexity of D(p) | ||

d.param(p) | void | no worse than the complexity of D(p) | ||

d(g) | T | With ,
the sequence of numbers
returned by successive invocations
with the same object g
is randomly distributed
according to the associated
p(z |{p})
or
function. | amortized constant number of invocations of g | |

d(g,p) | T | The sequence of numbers
returned by successive invocations
with the same objects g and p
is randomly distributed
according to the associated
p(z |{p})
or
function. | amortized constant number of invocations of g | |

x.min() | T | Returns glb. | constant | |

x.max() | T | Returns lub. | constant | |

x == y | bool | constant | ||

x != y | bool | !(x == y). | same as x == y. | |

os << x | reference to the type of os | |||

is >> d | reference to the type of is | If bad input is encountered,
ensures that d is unchanged by the operation
and
calls is.setstate(ios_base::failbit)
(which may throw ios_base::failure ([iostate.flags])). Preconditions: is provides a textual representation
that was previously written
using an os whose imbued locale
and whose type's template specialization arguments
charT and traits
were the same as those of is. |

The sequence of numbers
produced by repeated invocations of d(g)
shall be independent of any invocation of
os << d
or of
any const member function of D
between any of the invocations of d(g).

If a textual representation is written using os << x
and that representation is restored
into the same or a different object y
of the same type using is >> y,
repeated invocations of y(g)
shall produce the same sequence of numbers
as would repeated invocations of x(g).

P shall meet the
*Cpp17CopyConstructible* (Table 32),
*Cpp17CopyAssignable* (Table 34),
and
*Cpp17EqualityComparable* (Table 28) requirements.

For each of the constructors of D
taking arguments corresponding to parameters of the distribution,
P shall have a corresponding constructor
subject to the same requirements
and taking arguments identical in number, type, and default values.

Moreover,
for each of the member functions of D
that return values corresponding to parameters of the distribution,
P shall have a corresponding member function
with the identical name, type, and semantics.