[rand]

# 29 Numerics library [[numerics]](./#numerics)

## 29.5 Random number generation [rand]

### [29.5.1](#general) General [[rand.general]](rand.general)

[1](#general-1)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L1279)

Subclause [rand] defines a facility
for generating (pseudo-)random numbers[.](#general-1.sentence-1)

[2](#general-2)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L1283)

In addition to a few utilities,
four categories of entities are described:[*uniform random bit generators*](#def:uniform_random_bit_generators),[*random number engines*](#def:random_number_engines),[*random number engine adaptors*](#def:random_number_engine_adaptors),
and[*random number distributions*](#def:random_number_distributions)[.](#general-2.sentence-1)

These categorizations are applicable
to types that meet the corresponding requirements,
to objects instantiated from such types,
and to templates producing such types when instantiated[.](#general-2.sentence-2)

[*Note [1](#general-note-1)*:

These entities are specified in such a way
 as to permit the binding
 of any uniform random bit generator object e as the argument
 to any random number distribution object d,
 thus producing a zero-argument function object
 such as given by bind(d,e)[.](#general-2.sentence-3)

â *end note*]

[3](#general-3)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L1306)

Each of the entities specified in [rand]
has an associated arithmetic type ([[basic.fundamental]](basic.fundamental "6.9.2 Fundamental types"))
identified as result_type[.](#general-3.sentence-1)

With T as the result_type thus associated with such an entity,
that entity is characterized:

- [(3.1)](#general-3.1)

as [*boolean*](#def:boolean) or equivalently as [*boolean-valued*](#def:boolean-valued),
 if T is bool;

- [(3.2)](#general-3.2)

otherwise
 as [*integral*](#def:integral) or equivalently as [*integer-valued*](#def:integer-valued),
 if numeric_limits<T>​::​is_integer is true;

- [(3.3)](#general-3.3)

otherwise
 as [*floating-point*](#def:floating-point) or equivalently as [*real-valued*](#def:real-valued)[.](#general-3.sentence-2)

If integer-valued,
an entity may optionally be further characterized as[*signed*](#def:signed) or [*unsigned*](#def:unsigned),
according to numeric_limits<T>​::​is_signed[.](#general-3.sentence-3)

[4](#general-4)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L1331)

Unless otherwise specified,
all descriptions of calculations
in [rand]
use mathematical real numbers[.](#general-4.sentence-1)

[5](#general-5)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L1337)

Throughout [rand],
the operatorsbitand, bitor, and xor denote the respective conventional bitwise operations[.](#general-5.sentence-1)

Further:

- [(5.1)](#general-5.1)

the operator rshift denotes a bitwise right shift
 with zero-valued bits appearing in the high bits of the result, and

- [(5.2)](#general-5.2)

the operator lshiftw denotes a bitwise left shift
 with zero-valued bits appearing in the low bits of the result,
 and whose result is always taken modulo 2w[.](#general-5.sentence-2)

### [29.5.2](#synopsis) Header <random> synopsis [[rand.synopsis]](rand.synopsis)

#include <initializer_list> // see [[initializer.list.syn]](initializer.list.syn "17.11.2 Header <initializer_­list> synopsis")namespace std {// [[rand.req.urng]](#req.urng "29.5.3.3 Uniform random bit generator requirements"), uniform random bit generator requirementstemplate<class G>concept uniform_random_bit_generator = *see below*; // freestanding// [[rand.eng.lcong]](#eng.lcong "29.5.4.2 Class template linear_­congruential_­engine"), class template linear_congruential_enginetemplate<class UIntType, UIntType a, UIntType c, UIntType m>class linear_congruential_engine; // partially freestanding// [[rand.eng.mers]](#eng.mers "29.5.4.3 Class template mersenne_­twister_­engine"), class template mersenne_twister_enginetemplate<class UIntType, size_t w, size_t n, size_t m, size_t r,
 UIntType a, size_t u, UIntType d, size_t s,
 UIntType b, size_t t,
 UIntType c, size_t l, UIntType f>class mersenne_twister_engine; // [[rand.eng.sub]](#eng.sub "29.5.4.4 Class template subtract_­with_­carry_­engine"), class template subtract_with_carry_enginetemplate<class UIntType, size_t w, size_t s, size_t r>class subtract_with_carry_engine; // partially freestanding// [[rand.adapt.disc]](#adapt.disc "29.5.5.2 Class template discard_­block_­engine"), class template discard_block_enginetemplate<class Engine, size_t p, size_t r>class discard_block_engine; // partially freestanding// [[rand.adapt.ibits]](#adapt.ibits "29.5.5.3 Class template independent_­bits_­engine"), class template independent_bits_enginetemplate<class Engine, size_t w, class UIntType>class independent_bits_engine; // partially freestanding// [[rand.adapt.shuf]](#adapt.shuf "29.5.5.4 Class template shuffle_­order_­engine"), class template shuffle_order_enginetemplate<class Engine, size_t k>class shuffle_order_engine; // [[rand.eng.philox]](#eng.philox "29.5.4.5 Class template philox_­engine"), class template philox_enginetemplate<class UIntType, size_t w, size_t n, size_t r, UIntType... consts>class philox_engine; // partially freestanding// [[rand.predef]](#predef "29.5.6 Engines and engine adaptors with predefined parameters"), engines and engine adaptors with predefined parametersusing minstd_rand0 = *see below*; // freestandingusing minstd_rand = *see below*; // freestandingusing mt19937 = *see below*; // freestandingusing mt19937_64 = *see below*; // freestandingusing ranlux24_base = *see below*; // freestandingusing ranlux48_base = *see below*; // freestandingusing ranlux24 = *see below*; // freestandingusing ranlux48 = *see below*; // freestandingusing knuth_b = *see below*; using philox4x32 = *see below*; // freestandingusing philox4x64 = *see below*; // freestandingusing default_random_engine = *see below*; // [[rand.device]](#device "29.5.7 Class random_­device"), class random_deviceclass random_device; // [[rand.util.seedseq]](#util.seedseq "29.5.8.1 Class seed_­seq"), class seed_seqclass seed_seq; // [[rand.util.canonical]](#util.canonical "29.5.8.2 Function template generate_­canonical"), function template generate_canonicaltemplate<class RealType, size_t digits, class URBG> RealType generate_canonical(URBG& g); namespace ranges {// [[alg.rand.generate]](alg.rand.generate "26.12.2 generate_­random"), generate_randomtemplate<class R, class G>requires [output_range](range.refinements#concept:output_range "25.4.6 Other range refinements [range.refinements]")<R, invoke_result_t<G&>> &&[uniform_random_bit_generator](#concept:uniform_random_bit_generator "29.5.3.3 Uniform random bit generator requirements [rand.req.urng]")<remove_cvref_t<G>>constexpr borrowed_iterator_t<R> generate_random(R&& r, G&& g); template<class G, [output_iterator](iterator.concept.output#concept:output_iterator "24.3.4.10 Concept output_­iterator [iterator.concept.output]")<invoke_result_t<G&>> O, [sentinel_for](iterator.concept.sentinel#concept:sentinel_for "24.3.4.7 Concept sentinel_­for [iterator.concept.sentinel]")<O> S>requires [uniform_random_bit_generator](#concept:uniform_random_bit_generator "29.5.3.3 Uniform random bit generator requirements [rand.req.urng]")<remove_cvref_t<G>>constexpr O generate_random(O first, S last, G&& g); template<class R, class G, class D>requires [output_range](range.refinements#concept:output_range "25.4.6 Other range refinements [range.refinements]")<R, invoke_result_t<D&, G&>> && [invocable](concept.invocable#concept:invocable "18.7.2 Concept invocable [concept.invocable]")<D&, G&> &&[uniform_random_bit_generator](#concept:uniform_random_bit_generator "29.5.3.3 Uniform random bit generator requirements [rand.req.urng]")<remove_cvref_t<G>> && is_arithmetic_v<invoke_result_t<D&, G&>>constexpr borrowed_iterator_t<R> generate_random(R&& r, G&& g, D&& d); template<class G, class D, [output_iterator](iterator.concept.output#concept:output_iterator "24.3.4.10 Concept output_­iterator [iterator.concept.output]")<invoke_result_t<D&, G&>> O, [sentinel_for](iterator.concept.sentinel#concept:sentinel_for "24.3.4.7 Concept sentinel_­for [iterator.concept.sentinel]")<O> S>requires [invocable](concept.invocable#concept:invocable "18.7.2 Concept invocable [concept.invocable]")<D&, G&> && [uniform_random_bit_generator](#concept:uniform_random_bit_generator "29.5.3.3 Uniform random bit generator requirements [rand.req.urng]")<remove_cvref_t<G>> && is_arithmetic_v<invoke_result_t<D&, G&>>constexpr O generate_random(O first, S last, G&& g, D&& d); }// [[rand.dist.uni.int]](#dist.uni.int "29.5.9.2.1 Class template uniform_­int_­distribution"), class template uniform_int_distributiontemplate<class IntType = int>class uniform_int_distribution; // partially freestanding// [[rand.dist.uni.real]](#dist.uni.real "29.5.9.2.2 Class template uniform_­real_­distribution"), class template uniform_real_distributiontemplate<class RealType = double>class uniform_real_distribution; // [[rand.dist.bern.bernoulli]](#dist.bern.bernoulli "29.5.9.3.1 Class bernoulli_­distribution"), class bernoulli_distributionclass bernoulli_distribution; // [[rand.dist.bern.bin]](#dist.bern.bin "29.5.9.3.2 Class template binomial_­distribution"), class template binomial_distributiontemplate<class IntType = int>class binomial_distribution; // [[rand.dist.bern.geo]](#dist.bern.geo "29.5.9.3.3 Class template geometric_­distribution"), class template geometric_distributiontemplate<class IntType = int>class geometric_distribution; // [[rand.dist.bern.negbin]](#dist.bern.negbin "29.5.9.3.4 Class template negative_­binomial_­distribution"), class template negative_binomial_distributiontemplate<class IntType = int>class negative_binomial_distribution; // [[rand.dist.pois.poisson]](#dist.pois.poisson "29.5.9.4.1 Class template poisson_­distribution"), class template poisson_distributiontemplate<class IntType = int>class poisson_distribution; // [[rand.dist.pois.exp]](#dist.pois.exp "29.5.9.4.2 Class template exponential_­distribution"), class template exponential_distributiontemplate<class RealType = double>class exponential_distribution; // [[rand.dist.pois.gamma]](#dist.pois.gamma "29.5.9.4.3 Class template gamma_­distribution"), class template gamma_distributiontemplate<class RealType = double>class gamma_distribution; // [[rand.dist.pois.weibull]](#dist.pois.weibull "29.5.9.4.4 Class template weibull_­distribution"), class template weibull_distributiontemplate<class RealType = double>class weibull_distribution; // [[rand.dist.pois.extreme]](#dist.pois.extreme "29.5.9.4.5 Class template extreme_­value_­distribution"), class template extreme_value_distributiontemplate<class RealType = double>class extreme_value_distribution; // [[rand.dist.norm.normal]](#dist.norm.normal "29.5.9.5.1 Class template normal_­distribution"), class template normal_distributiontemplate<class RealType = double>class normal_distribution; // [[rand.dist.norm.lognormal]](#dist.norm.lognormal "29.5.9.5.2 Class template lognormal_­distribution"), class template lognormal_distributiontemplate<class RealType = double>class lognormal_distribution; // [[rand.dist.norm.chisq]](#dist.norm.chisq "29.5.9.5.3 Class template chi_­squared_­distribution"), class template chi_squared_distributiontemplate<class RealType = double>class chi_squared_distribution; // [[rand.dist.norm.cauchy]](#dist.norm.cauchy "29.5.9.5.4 Class template cauchy_­distribution"), class template cauchy_distributiontemplate<class RealType = double>class cauchy_distribution; // [[rand.dist.norm.f]](#dist.norm.f "29.5.9.5.5 Class template fisher_­f_­distribution"), class template fisher_f_distributiontemplate<class RealType = double>class fisher_f_distribution; // [[rand.dist.norm.t]](#dist.norm.t "29.5.9.5.6 Class template student_­t_­distribution"), class template student_t_distributiontemplate<class RealType = double>class student_t_distribution; // [[rand.dist.samp.discrete]](#dist.samp.discrete "29.5.9.6.1 Class template discrete_­distribution"), class template discrete_distributiontemplate<class IntType = int>class discrete_distribution; // [[rand.dist.samp.pconst]](#dist.samp.pconst "29.5.9.6.2 Class template piecewise_­constant_­distribution"), class template piecewise_constant_distributiontemplate<class RealType = double>class piecewise_constant_distribution; // [[rand.dist.samp.plinear]](#dist.samp.plinear "29.5.9.6.3 Class template piecewise_­linear_­distribution"), class template piecewise_linear_distributiontemplate<class RealType = double>class piecewise_linear_distribution;}

### [29.5.3](#req) Requirements [[rand.req]](rand.req)

#### [29.5.3.1](#req.genl) General requirements [[rand.req.genl]](rand.req.genl)

[1](#req.genl-1)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L1557)

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

- [(1.1)](#req.genl-1.1)

  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](#req.seedseq "29.5.3.2 Seed sequence requirements [rand.req.seedseq]")[.](#req.genl-1.1.sentence-1)

- [(1.2)](#req.genl-1.2)

  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](#req.urng "29.5.3.3 Uniform random bit generator requirements [rand.req.urng]")[.](#req.genl-1.2.sentence-1)

- [(1.3)](#req.genl-1.3)

  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](#req.eng "29.5.3.4 Random number engine requirements [rand.req.eng]")[.](#req.genl-1.3.sentence-1)

- [(1.4)](#req.genl-1.4)

  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[.](#req.genl-1.4.sentence-1)

- [(1.5)](#req.genl-1.5)

  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[.](#req.genl-1.5.sentence-1)

- [(1.6)](#req.genl-1.6)

  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[.](#req.genl-1.6.sentence-1)

[2](#req.genl-2)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L1617)

Throughout [rand],
phrases of the form âx is an iterator of a specific kindâ
shall be interpreted as equivalent to the more formal requirement that
âx is a value
of a type meeting the requirements
of the specified iterator typeâ[.](#req.genl-2.sentence-1)

[3](#req.genl-3)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L1625)

Throughout [rand],
any constructor that can be called with a single argument
and that meets a requirement specified in this subclause
shall be declared explicit[.](#req.genl-3.sentence-1)

#### [29.5.3.2](#req.seedseq) Seed sequence requirements [[rand.req.seedseq]](rand.req.seedseq)

[1](#req.seedseq-1)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L1638)

A [*seed sequence*](#def:seed_sequence "29.5.3.2 Seed sequence requirements [rand.req.seedseq]") is an object
 that consumes a sequence
 of integer-valued data
 and produces a requested number
 of unsigned integer values i, 0â¤i<232,
 based on the consumed data[.](#req.seedseq-1.sentence-1)

[*Note [1](#req.seedseq-note-1)*:

Such an object provides a mechanism
 to avoid replication of streams of random variates[.](#req.seedseq-1.sentence-2)

This can be useful, for example, in applications
 requiring large numbers of random number engines[.](#req.seedseq-1.sentence-3)

â *end note*]

[2](#req.seedseq-2)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L1653)

A class S meets the requirements
of a seed sequence
if the expressions shown
in Table [126](#tab:rand.req.seedseq "Table 126: Seed sequence requirements") are valid and have the indicated semantics,
and if S also meets all other requirements
of [[rand.req.seedseq]](#req.seedseq "29.5.3.2 Seed sequence requirements")[.](#req.seedseq-2.sentence-1)

In Table [126](#tab:rand.req.seedseq "Table 126: Seed sequence requirements") and throughout this subclause:

- [(2.1)](#req.seedseq-2.1)

T is the type named by S's associated result_type;

- [(2.2)](#req.seedseq-2.2)

q is a value of type S and r is a value of type S or const S;

- [(2.3)](#req.seedseq-2.3)

ib and ie are input iterators
 with an unsigned integer value_type of at least 32 bits;

- [(2.4)](#req.seedseq-2.4)

rb and re are mutable random access iterators
 with an unsigned integer value_type of at least 32 bits;

- [(2.5)](#req.seedseq-2.5)

ob is an output iterator;
 and

- [(2.6)](#req.seedseq-2.6)

il is a value of type initializer_list<T>[.](#req.seedseq-2.sentence-2)

Table [126](#tab:rand.req.seedseq) — Seed sequence requirements [[tab:rand.req.seedseq]](./tab:rand.req.seedseq)  

| [ð](#tab:rand.req.seedseq-row-1)<br>**Expression** | **Return type** | **Pre/post-condition** | **Complexity** |
| --- | --- | --- | --- |
| [ð](#tab:rand.req.seedseq-row-2)<br>S​::​result_type | T | T is an [unsigned integer type](basic.fundamental#def:type,unsigned_integer "6.9.2 Fundamental types [basic.fundamental]")  of at least 32 bits[.](#tab:rand.req.seedseq-row-2-column-3-sentence-1) |  |
| [ð](#tab:rand.req.seedseq-row-3)<br>S() |  | Creates a seed sequence  with the same initial state as all other default-constructed seed sequences  of type S[.](#tab:rand.req.seedseq-row-3-column-3-sentence-1) | constant |
| [ð](#tab:rand.req.seedseq-row-4)<br>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)[.](#tab:rand.req.seedseq-row-4-column-3-sentence-1) | O(ieâib) |
| [ð](#tab:rand.req.seedseq-row-5)<br>S(il) |  | Same as S(il.begin(), il.end())[.](#tab:rand.req.seedseq-row-5-column-3-sentence-1) | same as S(il.begin(), il.end()) |
| [ð](#tab:rand.req.seedseq-row-6)<br>q.generate(rb,re) | void | Does nothing if rb == re[.](#tab:rand.req.seedseq-row-6-column-3-sentence-1)<br>Otherwise,  fills the supplied sequence [rb,re)  with 32-bit quantities  that depend on the sequence supplied to the constructor  and possibly also depend on the history  of generate's previous invocations[.](#tab:rand.req.seedseq-row-6-column-3-sentence-2) | O(reârb) |
| [ð](#tab:rand.req.seedseq-row-7)<br>r.size() | size_t | The number of 32-bit units  that would be copied  by a call to r.param[.](#tab:rand.req.seedseq-row-7-column-3-sentence-1) | constant |
| [ð](#tab:rand.req.seedseq-row-8)<br>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[.](#tab:rand.req.seedseq-row-8-column-3-sentence-1) | O(r.size()) |

#### [29.5.3.3](#req.urng) Uniform random bit generator requirements [[rand.req.urng]](rand.req.urng)

[1](#req.urng-1)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L1771)

A [*uniform random bit generator*](#def: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[.](#req.urng-1.sentence-1)

[*Note [1](#req.urng-note-1)*:

The degree to which g's results
 approximate the ideal
 is often determined statistically[.](#req.urng-1.sentence-2)

â *end note*]

template<class G>concept [uniform_random_bit_generator](#concept:uniform_random_bit_generator "29.5.3.3 Uniform random bit generator requirements [rand.req.urng]") =[invocable](concept.invocable#concept:invocable "18.7.2 Concept invocable [concept.invocable]")<G&> && [unsigned_integral](concepts.arithmetic#concept:unsigned_integral "18.4.7 Arithmetic concepts [concepts.arithmetic]")<invoke_result_t<G&>> &&requires {{ G::min() } -> [same_as](concept.same#concept:same_as "18.4.2 Concept same_­as [concept.same]")<invoke_result_t<G&>>; { G::max() } -> [same_as](concept.same#concept:same_as "18.4.2 Concept same_­as [concept.same]")<invoke_result_t<G&>>; requires bool_constant<(G::min() < G::max())>::value; };

[2](#req.urng-2)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L1797)

Let g be an object of type G[.](#req.urng-2.sentence-1)

G models[uniform_random_bit_generator](#concept:uniform_random_bit_generator "29.5.3.3 Uniform random bit generator requirements [rand.req.urng]") only if

- [(2.1)](#req.urng-2.1)

G​::​min() <= g(),

- [(2.2)](#req.urng-2.2)

g() <= G​::​max(), and

- [(2.3)](#req.urng-2.3)

g() has amortized constant complexity[.](#req.urng-2.sentence-2)

[3](#req.urng-3)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L1808)

A class G meets the [*uniform random bit generator*](#def:uniform_random_bit_generator) requirements ifG models [uniform_random_bit_generator](#concept:uniform_random_bit_generator "29.5.3.3 Uniform random bit generator requirements [rand.req.urng]"),invoke_result_t<G&> is an unsigned integer type ([[basic.fundamental]](basic.fundamental "6.9.2 Fundamental types")),
andG provides a nested [*typedef-name*](dcl.typedef#nt:typedef-name "9.2.4 The typedef specifier [dcl.typedef]") result_type that denotes the same type as invoke_result_t<G&>[.](#req.urng-3.sentence-1)

#### [29.5.3.4](#req.eng) Random number engine requirements [[rand.req.eng]](rand.req.eng)

[1](#req.eng-1)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L1824)

A [*random number engine*](#def:random_number_engine) (commonly shortened to [*engine*](#def: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[.](#req.eng-1.sentence-1)

[2](#req.eng-2)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L1833)

At any given time,e has a state ei for some integer i â¥ 0[.](#req.eng-2.sentence-1)

Upon construction,e has an initial state e0[.](#req.eng-2.sentence-2)

An engine's state may be established via
 a constructor,
 a seed function,
 assignment,
 or a suitable operator>>[.](#req.eng-2.sentence-3)

[3](#req.eng-3)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L1846)

E's specification shall define:

- [(3.1)](#req.eng-3.1)

the size of E's state
 in multiples of the size of result_type,
 given as an integral constant expression;

- [(3.2)](#req.eng-3.2)

the [*transition algorithm*](#def:transition_algorithm)TA by which e's state ei is advanced to its [*successor state*](#def:successor_state)ei+1;
 and

- [(3.3)](#req.eng-3.3)

the [*generation algorithm*](#def:generation_algorithm)GA by which an engine's state is mapped
 to a value of type result_type[.](#req.eng-3.sentence-1)

[4](#req.eng-4)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L1867)

A class E that meets the requirements
of a [uniform random bit generator](#req.urng "29.5.3.3 Uniform random bit generator requirements [rand.req.urng]") also meets the requirements
of a [*random number engine*](#def:random_number_engine) if the expressions shown
in Table [127](#tab:rand.req.eng "Table 127: Random number engine requirements") are valid and have the indicated semantics,
and if E also meets all other requirements
of [[rand.req.eng]](#req.eng "29.5.3.4 Random number engine requirements")[.](#req.eng-4.sentence-1)

In Table [127](#tab:rand.req.eng "Table 127: Random number engine requirements") and throughout this subclause:

- [(4.1)](#req.eng-4.1)

T is the type named by E's associated result_type;

- [(4.2)](#req.eng-4.2)

e is a value of E, v is an lvalue of E, x and y are (possibly const) values of E;

- [(4.3)](#req.eng-4.3)

s is a value of T;

- [(4.4)](#req.eng-4.4)

q is an lvalue
 meeting the requirements of a [seed sequence](#req.seedseq "29.5.3.2 Seed sequence requirements [rand.req.seedseq]");

- [(4.5)](#req.eng-4.5)

z is a value
 of type unsigned long long;

- [(4.6)](#req.eng-4.6)

os is an lvalue of the type of some class template specialization basic_ostream<charT, traits>;
 and

- [(4.7)](#req.eng-4.7)

is is an lvalue of the type of some class template specialization basic_istream<charT, traits>;

where charT and traits are constrained
according to [[strings]](strings "27 Strings library") and [[input.output]](input.output "31 Input/output library")[.](#req.eng-4.sentence-2)

Table [127](#tab:rand.req.eng) — Random number engine requirements [[tab:rand.req.eng]](./tab:rand.req.eng)  

| [ð](#tab:rand.req.eng-row-1)<br>**Expression** | **Return type** | **Pre/post-condition** | **Complexity** |
| --- | --- | --- | --- |
| [ð](#tab:rand.req.eng-row-2)<br>E() |  | Creates an engine  with the same initial state  as all other default-constructed engines  of type E[.](#tab:rand.req.eng-row-2-column-3-sentence-1) | O(size of state) |
| [ð](#tab:rand.req.eng-row-3)<br>E(x) |  | Creates an engine  that compares equal to x[.](#tab:rand.req.eng-row-3-column-3-sentence-1) | O(size of state) |
| [ð](#tab:rand.req.eng-row-4)<br>E(s) |  | Creates an engine  with initial state determined by s[.](#tab:rand.req.eng-row-4-column-3-sentence-1) | O(size of state) |
| [ð](#tab:rand.req.eng-row-5)<br>E(q)[240](#footnote-240 "This constructor (as well as the subsequent corresponding seed() function) can be particularly useful to applications requiring a large number of independent random sequences.") |  | Creates an engine  with an initial state  that depends on a sequence  produced by one call  to q.generate[.](#tab:rand.req.eng-row-5-column-3-sentence-1) | same as complexity of q.generate  called on a sequence  whose length is size of state |
| [ð](#tab:rand.req.eng-row-6)<br>e.seed() | void | *Postconditions*: e == E()[.](#tab:rand.req.eng-row-6-column-3-sentence-1) | same as E() |
| [ð](#tab:rand.req.eng-row-7)<br>e.seed(s) | void | *Postconditions*: e == E(s)[.](#tab:rand.req.eng-row-7-column-3-sentence-1) | same as E(s) |
| [ð](#tab:rand.req.eng-row-8)<br>e.seed(q) | void | *Postconditions*: e == E(q)[.](#tab:rand.req.eng-row-8-column-3-sentence-1) | same as E(q) |
| [ð](#tab:rand.req.eng-row-9)<br>e() | T | Advances e's state ei to  ei+1 =TA(ei)  and returns  GA(ei)[.](#tab:rand.req.eng-row-9-column-3-sentence-1) | per [[rand.req.urng]](#req.urng "29.5.3.3 Uniform random bit generator requirements") |
| [ð](#tab:rand.req.eng-row-10)<br>e.discard(z)[241](#footnote-241 "This operation is common in user code, and can often be implemented in an engine-specific manner so as to provide significant performance improvements over an equivalent naive loop that makes z consecutive calls e().") | void | Advances e's state ei  to ei+z  by any means equivalent to z consecutive calls e()[.](#tab:rand.req.eng-row-10-column-3-sentence-1) | no worse than the complexity  of z consecutive calls e() |
| [ð](#tab:rand.req.eng-row-11)<br>x == y | bool | This operator is an equivalence relation[.](#tab:rand.req.eng-row-11-column-3-sentence-1)<br>With Sx and Sy  as the infinite sequences of values  that would be generated  by repeated future calls  to x() and y(),  respectively,  returns true  if Sx=Sy;  else returns false[.](#tab:rand.req.eng-row-11-column-3-sentence-2) | O(size of state) |
| [ð](#tab:rand.req.eng-row-12)<br>x != y | bool | !(x == y)[.](#tab:rand.req.eng-row-12-column-3-sentence-1) | O(size of state) |

[5](#req.eng-5)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L2026)

E shall meet the[*Cpp17CopyConstructible*](utility.arg.requirements#:Cpp17CopyConstructible "16.4.4.2 Template argument requirements [utility.arg.requirements]") (Table [32](utility.arg.requirements#tab:cpp17.copyconstructible "Table 32: Cpp17CopyConstructible requirements (in addition to Cpp17MoveConstructible)"))
and [*Cpp17CopyAssignable*](utility.arg.requirements#:Cpp17CopyAssignable "16.4.4.2 Template argument requirements [utility.arg.requirements]") (Table [34](utility.arg.requirements#tab:cpp17.copyassignable "Table 34: Cpp17CopyAssignable requirements (in addition to Cpp17MoveAssignable)")) requirements[.](#req.eng-5.sentence-1)

These operations shall each be of complexity
no worse than O(size of state)[.](#req.eng-5.sentence-2)

[6](#req.eng-6)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L2033)

On hosted implementations,
the following expressions are well-formed and have the specified semantics[.](#req.eng-6.sentence-1)

[ð](#req.eng-itemdecl:1)

`os << x
`

[7](#req.eng-7)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L2042)

*Effects*: With os.*fmtflags* set toios_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[.](#req.eng-7.sentence-1)

In the output,
adjacent numbers are separated
by one or more space characters[.](#req.eng-7.sentence-2)

[8](#req.eng-8)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L2054)

*Postconditions*: The os.*fmtflags* and fill character are unchanged[.](#req.eng-8.sentence-1)

[9](#req.eng-9)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L2058)

*Result*: reference to the type of os[.](#req.eng-9.sentence-1)

[10](#req.eng-10)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L2062)

*Returns*: os[.](#req.eng-10.sentence-1)

[11](#req.eng-11)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L2066)

*Complexity*: O(size of state)

[ð](#req.eng-itemdecl:2)

`is >> v
`

[12](#req.eng-12)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L2076)

*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 argumentscharT and traits were respectively the same as those of is[.](#req.eng-12.sentence-1)

[13](#req.eng-13)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L2087)

*Effects*: With is.*fmtflags* set to ios_base​::​dec,
sets v's state
as determined by reading its textual representation from is[.](#req.eng-13.sentence-1)

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]](iostate.flags "31.5.4.4 Flags functions")))[.](#req.eng-13.sentence-2)

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[.](#req.eng-13.sentence-3)

[14](#req.eng-14)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L2104)

*Postconditions*: The is.*fmtflags* are unchanged[.](#req.eng-14.sentence-1)

[15](#req.eng-15)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L2108)

*Result*: reference to the type of is[.](#req.eng-15.sentence-1)

[16](#req.eng-16)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L2112)

*Returns*: is[.](#req.eng-16.sentence-1)

[17](#req.eng-17)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L2116)

*Complexity*: O(size of state)

[240)](#footnote-240)[240)](#footnoteref-240)

This constructor
 (as well as the subsequent corresponding seed() function)
 can be particularly useful
 to applications requiring
 a large number of independent random sequences[.](#footnote-240.sentence-1)

[241)](#footnote-241)[241)](#footnoteref-241)

This operation is common
 in user code,
 and can often be implemented
 in an engine-specific manner
 so as to provide significant performance improvements
 over an equivalent naive loop
 that makes z consecutive calls e()[.](#footnote-241.sentence-1)

#### [29.5.3.5](#req.adapt) Random number engine adaptor requirements [[rand.req.adapt]](rand.req.adapt)

[1](#req.adapt-1)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L2130)

A [*random number engine adaptor*](#def:random_number_engine_adaptor) (commonly shortened to [*adaptor*](#def: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[.](#req.adapt-1.sentence-1)

An engine b of type B adapted in this way
is termed a [*base engine*](#def:base_engine) in this context[.](#req.adapt-1.sentence-2)

The expression a.base() shall be valid and shall return a
const reference to a's base engine[.](#req.adapt-1.sentence-3)

[2](#req.adapt-2)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L2146)

The requirements of a random number engine type
shall be interpreted as follows
with respect to a random number engine adaptor type[.](#req.adapt-2.sentence-1)

[ð](#req.adapt-itemdecl:1)

`A::A();
`

[3](#req.adapt-3)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L2156)

*Effects*: The base engine is initialized
 as if by its default constructor[.](#req.adapt-3.sentence-1)

[ð](#req.adapt-itemdecl:2)

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

[4](#req.adapt-4)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L2167)

*Returns*: true if a1's base engine is equal to a2's base engine[.](#req.adapt-4.sentence-1)

Otherwise returns false[.](#req.adapt-4.sentence-2)

[ð](#req.adapt-itemdecl:3)

`A::A(result_type s);
`

[5](#req.adapt-5)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L2178)

*Effects*: The base engine is initialized
 with s[.](#req.adapt-5.sentence-1)

[ð](#req.adapt-itemdecl:4)

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

[6](#req.adapt-6)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L2189)

*Effects*: The base engine is initialized
 with q[.](#req.adapt-6.sentence-1)

[ð](#req.adapt-itemdecl:5)

`void seed();
`

[7](#req.adapt-7)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L2200)

*Effects*: With b as the base engine, invokes b.seed()[.](#req.adapt-7.sentence-1)

[ð](#req.adapt-itemdecl:6)

`void seed(result_type s);
`

[8](#req.adapt-8)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L2210)

*Effects*: With b as the base engine, invokes b.seed(s)[.](#req.adapt-8.sentence-1)

[ð](#req.adapt-itemdecl:7)

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

[9](#req.adapt-9)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L2220)

*Effects*: With b as the base engine, invokes b.seed(q)[.](#req.adapt-9.sentence-1)

[10](#req.adapt-10)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L2225)

A shall also meet
the following additional requirements:

- [(10.1)](#req.adapt-10.1)

  The complexity
 of each function
 shall not exceed the complexity
 of the corresponding function
 applied to the base engine[.](#req.adapt-10.1.sentence-1)

- [(10.2)](#req.adapt-10.2)

  The state
 of A shall include the state
 of its base engine[.](#req.adapt-10.2.sentence-1)
  The size of A's state
 shall be no less than the size of the base engine[.](#req.adapt-10.2.sentence-2)

- [(10.3)](#req.adapt-10.3)

  Copying A's state
 (e.g., during copy construction or copy assignment)
 shall include copying
 the state of the base engine of A[.](#req.adapt-10.3.sentence-1)

- [(10.4)](#req.adapt-10.4)

  The textual representation
 of A shall include
 the textual representation of its base engine[.](#req.adapt-10.4.sentence-1)

#### [29.5.3.6](#req.dist) Random number distribution requirements [[rand.req.dist]](rand.req.dist)

[1](#req.dist-1)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L2261)

A [*random number distribution*](#def:random_number_distribution) (commonly shortened to [*distribution*](#def:distribution))d of type D is a function object
returning values
that are distributed according to
an associated mathematical [*probability density function*](#def:probability_density_function)p(z) or according to
an associated [*discrete probability function*](#def:discrete_probability_function)P(zi)[.](#req.dist-1.sentence-1)

A distribution's specification
identifies its associated probability functionp(z) or P(zi)[.](#req.dist-1.sentence-2)

[2](#req.dist-2)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L2277)

An associated probability function is typically expressed
using certain externally-supplied quantities
known as the [*parameters of the distribution*](#def:parameters_of_the_distribution)[.](#req.dist-2.sentence-1)

Such distribution parameters are identified
in this context by writing, for example, p(z | a,b) or P(zi|a,b),
 to name specific parameters,
or by writing, for example, p(z |{p}) or P(zi|{p}),
 to denote a distribution's parameters p taken as a whole[.](#req.dist-2.sentence-2)

[3](#req.dist-3)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L2290)

A class D meets the requirements
of a [*random number distribution*](#def:random_number_distribution) if the expressions shown
in Table [128](#tab:rand.req.dist "Table 128: Random number distribution requirements") are valid and have the indicated semantics,
and if D and its associated types
also meet all other requirements
of [[rand.req.dist]](#req.dist "29.5.3.6 Random number distribution requirements")[.](#req.dist-3.sentence-1)

In Table [128](#tab:rand.req.dist "Table 128: Random number distribution requirements") and throughout this subclause,

- [(3.1)](#req.dist-3.1)

T is the type named by D's associated result_type;

- [(3.2)](#req.dist-3.2)

P is the type named by D's associated param_type;

- [(3.3)](#req.dist-3.3)

d is a
 value of D,
 and x and y are (possibly const) values of D;

- [(3.4)](#req.dist-3.4)

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;

- [(3.5)](#req.dist-3.5)

p is a (possibly const) value of P;

- [(3.6)](#req.dist-3.6)

g, g1, and g2 are lvalues of a type
 meeting the requirements
 of a [uniform random bit generator](#req.urng "29.5.3.3 Uniform random bit generator requirements [rand.req.urng]");

- [(3.7)](#req.dist-3.7)

os is an lvalue of the type of some class template specialization basic_ostream<charT, traits>;
 and

- [(3.8)](#req.dist-3.8)

is is an lvalue of the type of some class template specialization basic_istream<charT, traits>;

where charT and traits are constrained
according to [[strings]](strings "27 Strings library") and [[input.output]](input.output "31 Input/output library")[.](#req.dist-3.sentence-2)

Table [128](#tab:rand.req.dist) — Random number distribution requirements [[tab:rand.req.dist]](./tab:rand.req.dist)  

| [ð](#tab:rand.req.dist-row-1)<br>**Expression** | **Return type** | **Pre/post-condition** | **Complexity** |
| --- | --- | --- | --- |
| [ð](#tab:rand.req.dist-row-2)<br>D​::​result_type | T | T is an [arithmetic type](basic.fundamental#def:type,arithmetic "6.9.2 Fundamental types [basic.fundamental]")[.](#tab:rand.req.dist-row-2-column-3-sentence-1) |  |
| [ð](#tab:rand.req.dist-row-3)<br>D​::​param_type | P |  |  |
| [ð](#tab:rand.req.dist-row-4)<br>D() |  | Creates a distribution whose behavior is indistinguishable  from that of any other newly default-constructed distribution  of type D[.](#tab:rand.req.dist-row-4-column-3-sentence-1) | constant |
| [ð](#tab:rand.req.dist-row-5)<br>D(p) |  | Creates a distribution whose behavior is indistinguishable  from that of a distribution  newly constructed directly from the values used to construct p[.](#tab:rand.req.dist-row-5-column-3-sentence-1) | same as p's construction |
| [ð](#tab:rand.req.dist-row-6)<br>d.reset() | void | Subsequent uses of d do not depend  on values produced by any engine  prior to invoking reset[.](#tab:rand.req.dist-row-6-column-3-sentence-1) | constant |
| [ð](#tab:rand.req.dist-row-7)<br>x.param() | P | Returns a value  p such that D(p).param() == p[.](#tab:rand.req.dist-row-7-column-3-sentence-1) | no worse than the complexity of D(p) |
| [ð](#tab:rand.req.dist-row-8)<br>d.param(p) | void | *Postconditions*: d.param() == p[.](#tab:rand.req.dist-row-8-column-3-sentence-1) | no worse than the complexity of D(p) |
| [ð](#tab:rand.req.dist-row-9)<br>d(g) | T | With p=d.param(),  the sequence of numbers  returned by successive invocations  with the same object g  is randomly distributed  according to the associated  p(z |{p})  or  P(zi|{p})  function[.](#tab:rand.req.dist-row-9-column-3-sentence-1) | amortized constant number of invocations of g |
| [ð](#tab:rand.req.dist-row-10)<br>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  P(zi|{p})  function[.](#tab:rand.req.dist-row-10-column-3-sentence-1) | amortized constant number of invocations of g |
| [ð](#tab:rand.req.dist-row-11)<br>x.min() | T | Returns glb[.](#tab:rand.req.dist-row-11-column-3-sentence-1) | constant |
| [ð](#tab:rand.req.dist-row-12)<br>x.max() | T | Returns lub[.](#tab:rand.req.dist-row-12-column-3-sentence-1) | constant |
| [ð](#tab:rand.req.dist-row-13)<br>x == y | bool | This operator is an equivalence relation[.](#tab:rand.req.dist-row-13-column-3-sentence-1)<br>Returns true  if x.param() == y.param() and S1=S2,  where S1 and S2 are  the infinite sequences of values  that would be generated, respectively,  by repeated future calls  to x(g1) and y(g2)  whenever g1 == g2[.](#tab:rand.req.dist-row-13-column-3-sentence-2)<br>Otherwise returns false[.](#tab:rand.req.dist-row-13-column-3-sentence-3) | constant |
| [ð](#tab:rand.req.dist-row-14)<br>x != y | bool | !(x == y)[.](#tab:rand.req.dist-row-14-column-3-sentence-1) | same as x == y[.](#tab:rand.req.dist-row-14-column-4-sentence-1) |

[4](#req.dist-4)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L2455)

D shall meet the[*Cpp17CopyConstructible*](utility.arg.requirements#:Cpp17CopyConstructible "16.4.4.2 Template argument requirements [utility.arg.requirements]") (Table [32](utility.arg.requirements#tab:cpp17.copyconstructible "Table 32: Cpp17CopyConstructible requirements (in addition to Cpp17MoveConstructible)"))
and [*Cpp17CopyAssignable*](utility.arg.requirements#:Cpp17CopyAssignable "16.4.4.2 Template argument requirements [utility.arg.requirements]") (Table [34](utility.arg.requirements#tab:cpp17.copyassignable "Table 34: Cpp17CopyAssignable requirements (in addition to Cpp17MoveAssignable)")) requirements[.](#req.dist-4.sentence-1)

[5](#req.dist-5)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L2460)

The sequence of numbers
produced by repeated invocations of d(g) shall be independent of any invocation ofos << d or of
any const member function of D between any of the invocations of d(g)[.](#req.dist-5.sentence-1)

[6](#req.dist-6)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L2469)

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)[.](#req.dist-6.sentence-1)

[7](#req.dist-7)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L2478)

It is unspecified whether D​::​param_type is declared as a (nested) class or via a typedef[.](#req.dist-7.sentence-1)

In [rand],
declarations of D​::​param_type are in the form of typedefs
for convenience of exposition only[.](#req.dist-7.sentence-2)

[8](#req.dist-8)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L2487)

P shall meet the[*Cpp17CopyConstructible*](utility.arg.requirements#:Cpp17CopyConstructible "16.4.4.2 Template argument requirements [utility.arg.requirements]") (Table [32](utility.arg.requirements#tab:cpp17.copyconstructible "Table 32: Cpp17CopyConstructible requirements (in addition to Cpp17MoveConstructible)")),[*Cpp17CopyAssignable*](utility.arg.requirements#:Cpp17CopyAssignable "16.4.4.2 Template argument requirements [utility.arg.requirements]") (Table [34](utility.arg.requirements#tab:cpp17.copyassignable "Table 34: Cpp17CopyAssignable requirements (in addition to Cpp17MoveAssignable)")),
and[*Cpp17EqualityComparable*](utility.arg.requirements#:Cpp17EqualityComparable "16.4.4.2 Template argument requirements [utility.arg.requirements]") (Table [28](utility.arg.requirements#tab:cpp17.equalitycomparable "Table 28: Cpp17EqualityComparable requirements")) requirements[.](#req.dist-8.sentence-1)

[9](#req.dist-9)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L2494)

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[.](#req.dist-9.sentence-1)

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[.](#req.dist-9.sentence-2)

[10](#req.dist-10)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L2506)

P shall have a declaration of the formusing distribution_type = D;

[11](#req.dist-11)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L2512)

On hosted implementations,
the following expressions are well-formed and have the specified semantics[.](#req.dist-11.sentence-1)

[ð](#req.dist-itemdecl:1)

`os << x
`

[12](#req.dist-12)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L2521)

*Effects*: Writes to os a textual representation
for the parameters and the additional internal data of x[.](#req.dist-12.sentence-1)

[13](#req.dist-13)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L2526)

*Postconditions*: The os.*fmtflags* and fill character are unchanged[.](#req.dist-13.sentence-1)

[14](#req.dist-14)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L2530)

*Result*: reference to the type of os[.](#req.dist-14.sentence-1)

[15](#req.dist-15)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L2534)

*Returns*: os[.](#req.dist-15.sentence-1)

[ð](#req.dist-itemdecl:2)

`is >> d
`

[16](#req.dist-16)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L2544)

*Preconditions*: is provides a textual representation
that was previously written
using an os whose imbued locale
and whose type's template specialization argumentscharT and traits were the same as those of is[.](#req.dist-16.sentence-1)

[17](#req.dist-17)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L2553)

*Effects*: Restores from is the parameters and additional internal data of the lvalue d[.](#req.dist-17.sentence-1)

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]](iostate.flags "31.5.4.4 Flags functions")))[.](#req.dist-17.sentence-2)

[18](#req.dist-18)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L2563)

*Postconditions*: The is.*fmtflags* are unchanged[.](#req.dist-18.sentence-1)

[19](#req.dist-19)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L2567)

*Result*: reference to the type of is[.](#req.dist-19.sentence-1)

[20](#req.dist-20)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L2571)

*Returns*: is[.](#req.dist-20.sentence-1)

### [29.5.4](#eng) Random number engine class templates [[rand.eng]](rand.eng)

#### [29.5.4.1](#eng.general) General [[rand.eng.general]](rand.eng.general)

[1](#eng.general-1)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L2595)

Each type instantiated
from a class template specified in [[rand.eng]](#eng "29.5.4 Random number engine class templates") meets the requirements
of a [random number engine](#req.eng "29.5.3.4 Random number engine requirements [rand.req.eng]") type[.](#eng.general-1.sentence-1)

[2](#eng.general-2)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L2601)

Except where specified otherwise,
the complexity of each function
specified in [[rand.eng]](#eng "29.5.4 Random number engine class templates") is constant[.](#eng.general-2.sentence-1)

[3](#eng.general-3)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L2607)

Except where specified otherwise,
no function described in [[rand.eng]](#eng "29.5.4 Random number engine class templates") throws an exception[.](#eng.general-3.sentence-1)

[4](#eng.general-4)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L2612)

Every function described in [[rand.eng]](#eng "29.5.4 Random number engine class templates") that has a function parameter q of type Sseq& for a template type parameter named Sseq that is different from type seed_seq throws what and when the invocation of q.generate throws[.](#eng.general-4.sentence-1)

[5](#eng.general-5)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L2619)

Descriptions are provided in [[rand.eng]](#eng "29.5.4 Random number engine class templates") only for engine operations
that are not described in [[rand.req.eng]](#req.eng "29.5.3.4 Random number engine requirements") or for operations where there is additional semantic information[.](#eng.general-5.sentence-1)

In particular,
declarations for copy constructors,
for copy assignment operators,
for streaming operators,
and for equality and inequality operators
are not shown in the synopses[.](#eng.general-5.sentence-2)

[6](#eng.general-6)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L2631)

Each template specified in [[rand.eng]](#eng "29.5.4 Random number engine class templates") requires one or more relationships,
involving the value(s) of its constant template parameter(s), to hold[.](#eng.general-6.sentence-1)

A program instantiating any of these templates
is ill-formed
if any such required relationship fails to hold[.](#eng.general-6.sentence-2)

[7](#eng.general-7)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L2639)

For every random number engine and for every random number engine adaptor X defined in [[rand.eng]](#eng "29.5.4 Random number engine class templates") and in [[rand.adapt]](#adapt "29.5.5 Random number engine adaptor class templates"):

- [(7.1)](#eng.general-7.1)

if the constructortemplate<class Sseq> explicit X(Sseq& q); is called with a type Sseq that does not qualify as a seed sequence, then this
constructor shall not participate in overload resolution;

- [(7.2)](#eng.general-7.2)

if the member functiontemplate<class Sseq> void seed(Sseq& q); is called with a type Sseq that does not qualify as a seed sequence, then this
function shall not participate in overload resolution[.](#eng.general-7.sentence-1)

The extent to which an implementation determines that a type cannot be a seed sequence
is unspecified, except that as a minimum a type shall not qualify as a seed sequence
if it is implicitly convertible to X​::​result_type[.](#eng.general-7.sentence-2)

#### [29.5.4.2](#eng.lcong) Class template linear_congruential_engine [[rand.eng.lcong]](rand.eng.lcong)

[1](#eng.lcong-1)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L2670)

A linear_congruential_engine random number engine
produces unsigned integer random numbers[.](#eng.lcong-1.sentence-1)

The state xi of a linear_congruential_engine object x is of size 1 and consists of a single integer[.](#eng.lcong-1.sentence-2)

The transition algorithm
is a modular linear function of the formTA(xi)=(aâxi+c)modm;
the generation algorithm
is GA(xi)=xi+1[.](#eng.lcong-1.sentence-3)

[ð](#lib:linear_congruential_engine_)

namespace std {template<class UIntType, UIntType a, UIntType c, UIntType m>class linear_congruential_engine {public:// typesusing result_type = UIntType; // engine characteristicsstatic constexpr result_type multiplier = a; static constexpr result_type increment = c; static constexpr result_type modulus = m; static constexpr result_type min() { return c == 0u ? 1u: 0u; }static constexpr result_type max() { return m - 1u; }static constexpr result_type default_seed = 1u; // constructors and seeding functions linear_congruential_engine() : linear_congruential_engine(default_seed) {}explicit linear_congruential_engine(result_type s); template<class Sseq> explicit linear_congruential_engine(Sseq& q); void seed(result_type s = default_seed); template<class Sseq> void seed(Sseq& q); // equality operatorsfriend bool operator==(const linear_congruential_engine& x, const linear_congruential_engine& y); // generating functions result_type operator()(); void discard(unsigned long long z); // inserters and extractorstemplate<class charT, class traits>friend basic_ostream<charT, traits>&operator<<(basic_ostream<charT, traits>& os, // hostedconst linear_congruential_engine& x); template<class charT, class traits>friend basic_istream<charT, traits>&operator>>(basic_istream<charT, traits>& is, // hosted linear_congruential_engine& x); };}

[2](#eng.lcong-2)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L2729)

If the template parameterm is 0,
the modulus m used throughout [[rand.eng.lcong]](#eng.lcong "29.5.4.2 Class template linear_­congruential_­engine") is numeric_limits<result_type>​::​max() plus 1[.](#eng.lcong-2.sentence-1)

[*Note [1](#eng.lcong-note-1)*:

m need not be representable
 as a value of type result_type[.](#eng.lcong-2.sentence-2)

â *end note*]

[3](#eng.lcong-3)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L2740)

If the template parameterm is not 0,
the following relations shall hold: a < m and c < m[.](#eng.lcong-3.sentence-1)

[4](#eng.lcong-4)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L2748)

The textual representation
consists of
the value of xi[.](#eng.lcong-4.sentence-1)

[ð](#lib:linear_congruential_engine,constructor)

`explicit linear_congruential_engine(result_type s);
`

[5](#eng.lcong-5)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L2759)

*Effects*: If cmodm is 0 and smodm is 0,
 sets the engine's state to 1,
 otherwise sets the engine's state to smodm[.](#eng.lcong-5.sentence-1)

[ð](#lib:linear_congruential_engine,constructor_)

`template<class Sseq> explicit linear_congruential_engine(Sseq& q);
`

[6](#eng.lcong-6)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L2772)

*Effects*: With k=âlog2m32â and a an array (or equivalent)
 of length k+3,
 invokes q.generate(a+0, a+k+3) and then computes S=(âkâ1j=0aj+3â232j)modm[.](#eng.lcong-6.sentence-1)

If cmodm is 0 and S is 0,
 sets the engine's state to 1,
 else sets the engine's state
 to S[.](#eng.lcong-6.sentence-2)

#### [29.5.4.3](#eng.mers) Class template mersenne_twister_engine [[rand.eng.mers]](rand.eng.mers)

[1](#eng.mers-1)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L2793)

A mersenne_twister_engine random number
engine[242](#footnote-242 "The name of this engine refers, in part, to a property of its period: For properly-selected values of the parameters, the period is closely related to a large Mersenne prime number.") produces unsigned integer random numbers
in the closed interval [0,2wâ1][.](#eng.mers-1.sentence-1)

The
statexi of a mersenne_twister_engine object x is of size n and consists of a sequence X of n values of the type delivered by x;
all subscripts applied to X are to be taken modulo n[.](#eng.mers-1.sentence-2)

[2](#eng.mers-2)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L2812)

The transition algorithm
employs a twisted generalized feedback shift register
defined by shift values n and m, a twist value r,
and a conditional xor-mask a[.](#eng.mers-2.sentence-1)

To improve the uniformity of the result,
the bits of the raw shift register are additionally [*tempered*](#def:tempered) (i.e., scrambled) according to a bit-scrambling matrix
defined by values u, d, s, b, t, c, and â[.](#eng.mers-2.sentence-2)

The state transition is performed as follows:

- [(2.1)](#eng.mers-2.1)

  Concatenate
 the upper wâr bits of Xiân with
 the lower r bits of Xi+1ân to obtain an unsigned integer value Y[.](#eng.mers-2.1.sentence-1)

- [(2.2)](#eng.mers-2.2)

  With Î±=aâ(Ybitand1),
 set Xi to Xi+mânxor(Yrshift1)xorÎ±[.](#eng.mers-2.2.sentence-1)

The sequence X is initialized
with the help of an initialization multiplier f[.](#eng.mers-2.sentence-4)

[3](#eng.mers-3)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L2838)

The generation algorithm
 determines the unsigned integer values z1,z2,z3,z4 as follows,
 then delivers z4 as its result:

- [(3.1)](#eng.mers-3.1)

  Let z1=Xixor((Xirshiftu)bitandd)[.](#eng.mers-3.1.sentence-1)

- [(3.2)](#eng.mers-3.2)

  Let z2=z1xor((z1lshiftws)bitandb)[.](#eng.mers-3.2.sentence-1)

- [(3.3)](#eng.mers-3.3)

  Let z3=z2xor((z2lshiftwt)bitandc)[.](#eng.mers-3.3.sentence-1)

- [(3.4)](#eng.mers-3.4)

  Let z4=z3xor(z3rshiftâ)[.](#eng.mers-3.4.sentence-1)

[ð](#lib:mersenne_twister_engine_)

namespace std {template<class UIntType, size_t w, size_t n, size_t m, size_t r,
 UIntType a, size_t u, UIntType d, size_t s,
 UIntType b, size_t t,
 UIntType c, size_t l, UIntType f>class mersenne_twister_engine {public:// typesusing result_type = UIntType; // engine characteristicsstatic constexpr size_t word_size = w; static constexpr size_t state_size = n; static constexpr size_t shift_size = m; static constexpr size_t mask_bits = r; static constexpr UIntType xor_mask = a; static constexpr size_t tempering_u = u; static constexpr UIntType tempering_d = d; static constexpr size_t tempering_s = s; static constexpr UIntType tempering_b = b; static constexpr size_t tempering_t = t; static constexpr UIntType tempering_c = c; static constexpr size_t tempering_l = l; static constexpr UIntType initialization_multiplier = f; static constexpr result_type min() { return 0; }static constexpr result_type max() { return 2wâ1; }static constexpr result_type default_seed = 5489u; // constructors and seeding functions mersenne_twister_engine() : mersenne_twister_engine(default_seed) {}explicit mersenne_twister_engine(result_type value); template<class Sseq> explicit mersenne_twister_engine(Sseq& q); void seed(result_type value = default_seed); template<class Sseq> void seed(Sseq& q); // equality operatorsfriend bool operator==(const mersenne_twister_engine& x, const mersenne_twister_engine& y); // generating functions result_type operator()(); void discard(unsigned long long z); // inserters and extractorstemplate<class charT, class traits>friend basic_ostream<charT, traits>&operator<<(basic_ostream<charT, traits>& os, // hostedconst mersenne_twister_engine& x); template<class charT, class traits>friend basic_istream<charT, traits>&operator>>(basic_istream<charT, traits>& is, // hosted mersenne_twister_engine& x); };}

[4](#eng.mers-4)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L2911)

The following relations shall hold: 0 < m, m <= n, 2u < w, r <= w, u <= w, s <= w, t <= w, l <= w, w <= numeric_limits<UIntType>​::​digits, a <= (1u << w) - 1u, b <= (1u << w) - 1u, c <= (1u << w) - 1u, d <= (1u << w) - 1u,
and f <= (1u << w) - 1u[.](#eng.mers-4.sentence-1)

[5](#eng.mers-5)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L2929)

The textual representation
of xi consists of the values of Xiân,â¦,Xiâ1,
in that order[.](#eng.mers-5.sentence-1)

[ð](#lib:mersenne_twister_engine,constructor)

`explicit mersenne_twister_engine(result_type value);
`

[6](#eng.mers-6)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L2941)

*Effects*: Sets Xân to valuemod2w[.](#eng.mers-6.sentence-1)

Then, iteratively for i=1ân,â¦,â1, sets Xi to  
[fâ(Xiâ1xor(Xiâ1rshift(wâ2)))+imodn]mod2w[.](#eng.mers-6.sentence-2)

[7](#eng.mers-7)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L2954)

*Complexity*: O(n)[.](#eng.mers-7.sentence-1)

[ð](#lib:mersenne_twister_engine,constructor_)

`template<class Sseq> explicit mersenne_twister_engine(Sseq& q);
`

[8](#eng.mers-8)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L2965)

*Effects*: With k=âw/32â and a an array (or equivalent)
 of length nâk,
 invokes q.generate(a+0, a+nâk) and then, iteratively for i=ân,â¦,â1,
 sets Xi to (âkâ1j=0ak(i+n)+jâ232j)mod2w[.](#eng.mers-8.sentence-1)

Finally,
 if the most significant wâr bits of Xân are zero,
 and if each of the other resulting Xi is 0,
 changes Xân to 2wâ1[.](#eng.mers-8.sentence-2)

[242)](#footnote-242)[242)](#footnoteref-242)

The name of this engine refers, in part, to a property of its period:
 For properly-selected values of the parameters,
 the period is closely related to a large Mersenne prime number[.](#footnote-242.sentence-1)

#### [29.5.4.4](#eng.sub) Class template subtract_with_carry_engine [[rand.eng.sub]](rand.eng.sub)

[1](#eng.sub-1)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L2989)

A subtract_with_carry_engine random number engine
produces unsigned integer random numbers[.](#eng.sub-1.sentence-1)

[2](#eng.sub-2)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L2993)

The state xi of a subtract_with_carry_engine object x is of sizeO(r),
and consists of
a sequence X of r integer values 0â¤Xi<m=2w;
all subscripts applied to X are to be taken modulo r[.](#eng.sub-2.sentence-1)

The state xi additionally consists of an integer c (known as the [*carry*](#def:carry))
whose value is either 0 or 1[.](#eng.sub-2.sentence-2)

[3](#eng.sub-3)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L3006)

The state transition
is performed as follows:

- [(3.1)](#eng.sub-3.1)

  Let Y=XiâsâXiârâc[.](#eng.sub-3.1.sentence-1)

- [(3.2)](#eng.sub-3.2)

  Set Xi to y=Ymodm[.](#eng.sub-3.2.sentence-1)
  Set c to 1 if Y<0,
 otherwise set c to 0[.](#eng.sub-3.2.sentence-2)

[*Note [1](#eng.sub-note-1)*:

This algorithm corresponds
 to a modular linear function
 of the form TA(xi)=(aâxi)modb,
 where b is of the form mrâms+1 and a=bâ(bâ1)/m[.](#eng.sub-3.sentence-2)

â *end note*]

[4](#eng.sub-4)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L3027)

The generation algorithm
is given by GA(xi)=y,
where y is the value produced as a result
of advancing the engine's state as described above[.](#eng.sub-4.sentence-1)

[ð](#lib:subtract_with_carry_engine_)

namespace std {template<class UIntType, size_t w, size_t s, size_t r>class subtract_with_carry_engine {public:// typesusing result_type = UIntType; // engine characteristicsstatic constexpr size_t word_size = w; static constexpr size_t short_lag = s; static constexpr size_t long_lag = r; static constexpr result_type min() { return 0; }static constexpr result_type max() { return mâ1; }static constexpr uint_least32_t default_seed = 19780503u; // constructors and seeding functions subtract_with_carry_engine() : subtract_with_carry_engine(0u) {}explicit subtract_with_carry_engine(result_type value); template<class Sseq> explicit subtract_with_carry_engine(Sseq& q); void seed(result_type value = 0u); template<class Sseq> void seed(Sseq& q); // equality operatorsfriend bool operator==(const subtract_with_carry_engine& x, const subtract_with_carry_engine& y); // generating functions result_type operator()(); void discard(unsigned long long z); // inserters and extractorstemplate<class charT, class traits>friend basic_ostream<charT, traits>&operator<<(basic_ostream<charT, traits>& os, // hostedconst subtract_with_carry_engine& x); template<class charT, class traits>friend basic_istream<charT, traits>&operator>>(basic_istream<charT, traits>& is, // hosted subtract_with_carry_engine& x); };}

[5](#eng.sub-5)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L3079)

The following relations shall hold: 0u < s, s < r, 0 < w,
and w <= numeric_limits<UIntType>​::​digits[.](#eng.sub-5.sentence-1)

[6](#eng.sub-6)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L3087)

The textual representation
consists of the values of Xiâr,â¦,Xiâ1,
in that order, followed by c[.](#eng.sub-6.sentence-1)

[ð](#lib:subtract_with_carry_engine,constructor)

`explicit subtract_with_carry_engine(result_type value);
`

[7](#eng.sub-7)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L3099)

*Effects*: Sets the values of Xâr,â¦,Xâ1,
 in that order, as specified below[.](#eng.sub-7.sentence-1)

If Xâ1 is then 0,
 sets c to 1;
 otherwise sets c to 0[.](#eng.sub-7.sentence-2)

To set the values Xk,
 first construct e, a linear_congruential_engine object,
 as if by the following definition:linear_congruential_engine<uint_least32_t, 40014u, 0u, 2147483563u> e( value == 0u ? default_seed : static_cast<uint_least32_t>(value % 2147483563u));

Then, to set each Xk,
 obtain new values z0,â¦,znâ1 from n=âw/32â successive invocations
 of e[.](#eng.sub-7.sentence-4)

Set Xk to (ânâ1j=0zjâ232j)modm[.](#eng.sub-7.sentence-5)

[8](#eng.sub-8)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L3121)

*Complexity*: Exactly nâr invocations
 of e[.](#eng.sub-8.sentence-1)

[ð](#lib:subtract_with_carry_engine,constructor_)

`template<class Sseq> explicit subtract_with_carry_engine(Sseq& q);
`

[9](#eng.sub-9)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L3133)

*Effects*: With k=âw/32â and a an array (or equivalent)
 of length râk,
 invokes q.generate(a+0, a+râk) and then, iteratively for i=âr,â¦,â1,
 sets Xi to (âkâ1j=0ak(i+r)+jâ232j)modm[.](#eng.sub-9.sentence-1)

If Xâ1 is then 0,
 sets c to 1;
 otherwise sets c to 0[.](#eng.sub-9.sentence-2)

#### [29.5.4.5](#eng.philox) Class template philox_engine [[rand.eng.philox]](rand.eng.philox)

[1](#eng.philox-1)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L3154)

A philox_engine random number engine produces
unsigned integer random numbers in the interval [0, m),
where m=2w and
the template parameter w defines the range of the produced numbers[.](#eng.philox-1.sentence-1)

The state of a philox_engine object consists of
a sequence X of n unsigned integer values of width w,
a sequence K of n/2 values of result_type,
a sequence Y of n values of result_type, and
a scalar i, where

- [(1.1)](#eng.philox-1.1)

X is the interpretation of the unsigned integer [*counter*](#def:counter) valueZ:=ânâ1j=0Xjâ2wj of nâw bits,

- [(1.2)](#eng.philox-1.2)

K are keys, which are generated once from the seed (see constructors below)
and remain constant unless the seed function ([[rand.req.eng]](#req.eng "29.5.3.4 Random number engine requirements")) is invoked,

- [(1.3)](#eng.philox-1.3)

Y stores a batch of output values, and

- [(1.4)](#eng.philox-1.4)

i is an index for an element of the sequence Y[.](#eng.philox-1.sentence-2)

[2](#eng.philox-2)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L3177)

The generation algorithm returns Yi,
the value stored in the ith element of Y after applying
the transition algorithm[.](#eng.philox-2.sentence-1)

[3](#eng.philox-3)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L3182)

The state transition is performed as if by the following algorithm:i = i + 1if (i == n) {Y = Philox(K, X) // *see below*Z = Z + 1i = 0}

[4](#eng.philox-4)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L3193)

The Philox function maps the length-n/2 sequence K and
the length-n sequence X into a length-n output sequence Y[.](#eng.philox-4.sentence-1)

Philox applies an r-round substitution-permutation network to the values in X[.](#eng.philox-4.sentence-2)

A single round of the generation algorithm performs the following steps:

- [(4.1)](#eng.philox-4.1)

The output sequence Xâ² of the previous round
(X in case of the first round)
is permuted to obtain the intermediate state V:Vj=Xâ²fn(j) where j=0,â¦,nâ1 andfn(j) is defined in Table [129](#tab:rand.eng.philox.f "Table 129: Values for the word permutation <b>f</b>ï¿½"). Table [129](#tab:rand.eng.philox.f) — Values for the word permutation fn(j) [[tab:rand.eng.philox.f]](./tab:rand.eng.philox.f)  

| [ð](#tab:rand.eng.philox.f-row-1)<br>fn(j) | | **j** | | | |
| --- | --- | --- | --- | --- | --- |
| [ð](#tab:rand.eng.philox.f-row-2) | | 0 | 1 | 2 | 3 |
| [ð](#tab:rand.eng.philox.f-row-3)<br>**n** | 2 | 0 | 1 |  | |
| [ð](#tab:rand.eng.philox.f-row-4)<br> | 4 | 2 | 1 | 0 | 3 |
| [ð](#tab:rand.eng.philox.f-row-5)<br> |

  [*Note [1](#eng.philox-note-1)*:
  For n=2 the sequence is not permuted[.](#eng.philox-4.1.sentence-2)
 â *end note*]

- [(4.2)](#eng.philox-4.2)

The following computations are applied to the elements of the V sequence:X2k+0=mulhi(V2k,Mk,w)xorkeyqkxorV2k+1X2k+1=mullo(V2k,Mk,w) where:
  * [(4.2.1)](#eng.philox-4.2.1)

mullo(a, b, w) is
 the low half of the modular multiplication of a and b: (aâb)mod2w,

  * [(4.2.2)](#eng.philox-4.2.2)

mulhi(a, b, w) is
 the high half of the modular multiplication of a and b: (â(aâb)/2wâ),

  * [(4.2.3)](#eng.philox-4.2.3)

k=0,â¦,n/2â1 is the index in the sequences,

  * [(4.2.4)](#eng.philox-4.2.4)

q=0,â¦,râ1 is the index of the round,

  * [(4.2.5)](#eng.philox-4.2.5)

keyqk is the kth round key for round q, keyqk:=(Kk+qâCk)mod2w,

  * [(4.2.6)](#eng.philox-4.2.6)

Kk are the elements of the key sequence K,

  * [(4.2.7)](#eng.philox-4.2.7)

Mk is multipliers[k], and

  * [(4.2.8)](#eng.philox-4.2.8)

Ck is round_consts[k].

[5](#eng.philox-5)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L3261)

After r applications of the single-round function,Philox returns the sequence Y=Xâ²[.](#eng.philox-5.sentence-1)

[ð](#lib:philox_engine_)

namespace std {template<class UIntType, size_t w, size_t n, size_t r, UIntType... consts>class philox_engine {static constexpr size_t *array-size* = n / 2; // *exposition only*public:// typesusing result_type = UIntType; // engine characteristicsstatic constexpr size_t word_size = w; static constexpr size_t word_count = n; static constexpr size_t round_count = r; static constexpr array<result_type, *array-size*> multipliers; static constexpr array<result_type, *array-size>* round_consts; static constexpr result_type min() { return 0; }static constexpr result_type max() { return m - 1; }static constexpr result_type default_seed = 20111115u; // constructors and seeding functions philox_engine() : philox_engine(default_seed) {}explicit philox_engine(result_type value); template<class Sseq> explicit philox_engine(Sseq& q); void seed(result_type value = default_seed); template<class Sseq> void seed(Sseq& q); void set_counter(const array<result_type, n>& counter); // equality operatorsfriend bool operator==(const philox_engine& x, const philox_engine& y); // generating functions result_type operator()(); void discard(unsigned long long z); // inserters and extractorstemplate<class charT, class traits>friend basic_ostream<charT, traits>&operator<<(basic_ostream<charT, traits>& os, const philox_engine& x); // hostedtemplate<class charT, class traits>friend basic_istream<charT, traits>&operator>>(basic_istream<charT, traits>& is, philox_engine& x); // hosted};}

[6](#eng.philox-6)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L3313)

*Mandates*: 

- [(6.1)](#eng.philox-6.1)

sizeof...(consts) == n is true, and

- [(6.2)](#eng.philox-6.2)

n == 2 || n == 4 is true, and

- [(6.3)](#eng.philox-6.3)

0 < r is true, and

- [(6.4)](#eng.philox-6.4)

0 < w && w <= numeric_limits<UIntType>​::​digits is true[.](#eng.philox-6.sentence-1)

[7](#eng.philox-7)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L3322)

The template parameter pack consts represents
the Mk and Ck constants which are grouped as follows:[M0,C0,M1,C1,M2,C2,â¦,Mn/2â1,Cn/2â1][.](#eng.philox-7.sentence-1)

[8](#eng.philox-8)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L3327)

The textual representation consists of the values ofK0,â¦,Kn/2â1,X0,â¦,Xnâ1,i, in that order[.](#eng.philox-8.sentence-1)

[*Note [2](#eng.philox-note-2)*:

The stream extraction operator can reconstruct Y from K and X, as needed[.](#eng.philox-8.sentence-2)

â *end note*]

[ð](#lib:philox_engine,constructor)

`explicit philox_engine(result_type value);
`

[9](#eng.philox-9)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L3340)

*Effects*: Sets the K0 element of sequence K to valuemod2w[.](#eng.philox-9.sentence-1)

All elements of sequences X and K (except K0) are set to 0[.](#eng.philox-9.sentence-2)

The value of i is set to nâ1[.](#eng.philox-9.sentence-3)

[ð](#lib:philox_engine,constructor_)

`template<class Sseq> explicit philox_engine(Sseq& q);
`

[10](#eng.philox-10)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L3353)

*Effects*: With p=âw/32â and
an array (or equivalent) a of length (n/2)âp,
invokes q.generate(a + 0, a + n / 2 * p) and
then iteratively for k=0,â¦,n/2â1,
sets Kk to(âpâ1j=0akp+jâ232j)mod2w[.](#eng.philox-10.sentence-1)

All elements of sequence X are set to 0[.](#eng.philox-10.sentence-2)

The value of i is set to nâ1[.](#eng.philox-10.sentence-3)

[ð](#lib:set_counter,philox_engine)

`void set_counter(const array<result_type, n>& c);
`

[11](#eng.philox-11)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L3371)

*Effects*: For j=0,â¦,nâ1 sets Xj to Cnâ1âjmod2w[.](#eng.philox-11.sentence-1)

The value of i is set to nâ1[.](#eng.philox-11.sentence-2)

[*Note [3](#eng.philox-note-3)*:

The counter is the value Z introduced at the beginning of this subclause[.](#eng.philox-11.sentence-3)

â *end note*]

### [29.5.5](#adapt) Random number engine adaptor class templates [[rand.adapt]](rand.adapt)

#### [29.5.5.1](#adapt.general) General [[rand.adapt.general]](rand.adapt.general)

[1](#adapt.general-1)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L3393)

Each type instantiated
from a class template specified in [[rand.adapt]](#adapt "29.5.5 Random number engine adaptor class templates") meets the requirements
of a [random number engine adaptor](#req.adapt "29.5.3.5 Random number engine adaptor requirements [rand.req.adapt]") type[.](#adapt.general-1.sentence-1)

[2](#adapt.general-2)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L3399)

Except where specified otherwise,
the complexity of each function
specified in [[rand.adapt]](#adapt "29.5.5 Random number engine adaptor class templates") is constant[.](#adapt.general-2.sentence-1)

[3](#adapt.general-3)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L3405)

Except where specified otherwise,
no function described in [[rand.adapt]](#adapt "29.5.5 Random number engine adaptor class templates") throws an exception[.](#adapt.general-3.sentence-1)

[4](#adapt.general-4)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L3410)

Every function described in [[rand.adapt]](#adapt "29.5.5 Random number engine adaptor class templates") that has a function parameter q of type Sseq& for a template type parameter named Sseq that is different from type seed_seq throws what and when the invocation of q.generate throws[.](#adapt.general-4.sentence-1)

[5](#adapt.general-5)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L3417)

Descriptions are provided in [[rand.adapt]](#adapt "29.5.5 Random number engine adaptor class templates") only for adaptor operations
that are not described in subclause [[rand.req.adapt]](#req.adapt "29.5.3.5 Random number engine adaptor requirements") or for operations where there is additional semantic information[.](#adapt.general-5.sentence-1)

In particular,
declarations for copy constructors,
for copy assignment operators,
for streaming operators,
and for equality and inequality operators
are not shown in the synopses[.](#adapt.general-5.sentence-2)

[6](#adapt.general-6)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L3429)

Each template specified in [[rand.adapt]](#adapt "29.5.5 Random number engine adaptor class templates") requires one or more relationships,
involving the value(s) of its constant template parameter(s), to hold[.](#adapt.general-6.sentence-1)

A program instantiating any of these templates
is ill-formed
if any such required relationship fails to hold[.](#adapt.general-6.sentence-2)

#### [29.5.5.2](#adapt.disc) Class template discard_block_engine [[rand.adapt.disc]](rand.adapt.disc)

[1](#adapt.disc-1)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L3443)

A discard_block_engine random number engine adaptor
produces random numbers
selected from those produced by some base engine e[.](#adapt.disc-1.sentence-1)

The state xi of a discard_block_engine engine adaptor object x consists of the state ei of its base engine e and an additional integer n[.](#adapt.disc-1.sentence-2)

The size of the state is
 the size of e's state plus 1[.](#adapt.disc-1.sentence-3)

[2](#adapt.disc-2)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L3454)

The transition algorithm
discards all but r>0 values
from each block of p â¥ r values delivered by e[.](#adapt.disc-2.sentence-1)

The state transition is performed as follows:
If n â¥ r,
 advance the state of e from ei to ei+pâr and set n to 0[.](#adapt.disc-2.sentence-2)

In any case,
 then increment n and advance e's then-current state ej to ej+1[.](#adapt.disc-2.sentence-3)

[3](#adapt.disc-3)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L3467)

The generation algorithm
yields the value returned by the last invocation of e() while advancing e's state as described above[.](#adapt.disc-3.sentence-1)

[ð](#lib:discard_block_engine_)

namespace std {template<class Engine, size_t p, size_t r>class discard_block_engine {public:// typesusing result_type = typename Engine::result_type; // engine characteristicsstatic constexpr size_t block_size = p; static constexpr size_t used_block = r; static constexpr result_type min() { return Engine::min(); }static constexpr result_type max() { return Engine::max(); }// constructors and seeding functions discard_block_engine(); explicit discard_block_engine(const Engine& e); explicit discard_block_engine(Engine&& e); explicit discard_block_engine(result_type s); template<class Sseq> explicit discard_block_engine(Sseq& q); void seed(); void seed(result_type s); template<class Sseq> void seed(Sseq& q); // equality operatorsfriend bool operator==(const discard_block_engine& x, const discard_block_engine& y); // generating functions result_type operator()(); void discard(unsigned long long z); // property functionsconst Engine& base() const noexcept { return e; }// inserters and extractorstemplate<class charT, class traits>friend basic_ostream<charT, traits>&operator<<(basic_ostream<charT, traits>& os, const discard_block_engine& x); // hostedtemplate<class charT, class traits>friend basic_istream<charT, traits>&operator>>(basic_istream<charT, traits>& is, discard_block_engine& x); // hostedprivate: Engine e; // *exposition only* size_t n; // *exposition only*};}

[4](#adapt.disc-4)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L3523)

The following relations shall hold: 0 < r and r <= p[.](#adapt.disc-4.sentence-1)

[5](#adapt.disc-5)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L3529)

The textual representation
consists of
 the textual representation of e followed by
 the value of n[.](#adapt.disc-5.sentence-1)

[6](#adapt.disc-6)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L3536)

In addition to its behavior
pursuant to subclause [[rand.req.adapt]](#req.adapt "29.5.3.5 Random number engine adaptor requirements"),
each constructor that is not a copy constructor
sets n to 0[.](#adapt.disc-6.sentence-1)

#### [29.5.5.3](#adapt.ibits) Class template independent_bits_engine [[rand.adapt.ibits]](rand.adapt.ibits)

[1](#adapt.ibits-1)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L3550)

An independent_bits_engine random number engine adaptor
combines random numbers
that are produced by some base engine e,
so as to produce random numbers
with a specified number of bits w[.](#adapt.ibits-1.sentence-1)

The state xi of an independent_bits_engine engine adaptor object x consists of
 the state ei of its base engine e;
the size of the state is
 the size of e's state[.](#adapt.ibits-1.sentence-2)

[2](#adapt.ibits-2)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L3565)

The transition and generation algorithms
are described in terms
of the following integral constants:

- [(2.1)](#adapt.ibits-2.1)

  Let R=e.max() - e.min() + 1 and m=âlog2Râ[.](#adapt.ibits-2.1.sentence-1)

- [(2.2)](#adapt.ibits-2.2)

  With n as determined below,
 let w0=âw/nâ, n0=nâwmodn, y0=2w0âR/2w0â,
 and y1=2w0+1âR/2w0+1â[.](#adapt.ibits-2.2.sentence-1)

- [(2.3)](#adapt.ibits-2.3)

  Let n=âw/mâ if and only if the relation Rây0â¤ây0/nâ holds as a result[.](#adapt.ibits-2.3.sentence-1)
  Otherwise let n=1+âw/mâ[.](#adapt.ibits-2.3.sentence-2)

[*Note [1](#adapt.ibits-note-1)*:

The relation w=n0w0+(nân0)(w0+1) always holds[.](#adapt.ibits-2.sentence-2)

â *end note*]

[3](#adapt.ibits-3)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L3598)

The transition algorithm
is carried out by invoking e() as often as needed to obtain n0 values less than y0+e.min() and nân0 values less than y1+e.min()[.](#adapt.ibits-3.sentence-1)

[4](#adapt.ibits-4)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L3605)

The generation algorithm
uses the values produced
while advancing the state as described above
to yield a quantity S obtained as if by the following algorithm:S = 0;for (k = 0; kâ n0; k += 1) {do u = e() - e.min(); while (uâ¥y0); S = 2w0âS+umod2w0;}for (k = n0; k â n; k += 1) {do u = e() - e.min(); while (uâ¥y1); S = 2w0+1âS+umod2w0+1;}

[ð](#lib:independent_bits_engine_)

namespace std {template<class Engine, size_t w, class UIntType>class independent_bits_engine {public:// typesusing result_type = UIntType; // engine characteristicsstatic constexpr result_type min() { return 0; }static constexpr result_type max() { return 2wâ1; }// constructors and seeding functions independent_bits_engine(); explicit independent_bits_engine(const Engine& e); explicit independent_bits_engine(Engine&& e); explicit independent_bits_engine(result_type s); template<class Sseq> explicit independent_bits_engine(Sseq& q); void seed(); void seed(result_type s); template<class Sseq> void seed(Sseq& q); // equality operatorsfriend bool operator==(const independent_bits_engine& x, const independent_bits_engine& y); // generating functions result_type operator()(); void discard(unsigned long long z); // property functionsconst Engine& base() const noexcept { return e; }// inserters and extractorstemplate<class charT, class traits>friend basic_ostream<charT, traits>&operator<<(basic_ostream<charT, traits>& os, const independent_bits_engine& x); // hostedtemplate<class charT, class traits>friend basic_istream<charT, traits>&operator>>(basic_istream<charT, traits>& is, independent_bits_engine& x); // hostedprivate: Engine e; // *exposition only*};}

[5](#adapt.ibits-5)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L3671)

The following relations shall hold: 0 < w and w <= numeric_limits<result_type>​::​digits[.](#adapt.ibits-5.sentence-1)

[6](#adapt.ibits-6)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L3677)

The textual representation
consists of the textual representation of e[.](#adapt.ibits-6.sentence-1)

#### [29.5.5.4](#adapt.shuf) Class template shuffle_order_engine [[rand.adapt.shuf]](rand.adapt.shuf)

[1](#adapt.shuf-1)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L3688)

A shuffle_order_engine random number engine adaptor
produces the same random numbers
that are produced by some base engine e,
but delivers them in a different sequence[.](#adapt.shuf-1.sentence-1)

The state xi of a shuffle_order_engine engine adaptor object x consists of
 the state ei of its base engine e,
 an additional value Y of the type delivered by e,
and
 an additional sequence V of k values
 also of the type delivered by e[.](#adapt.shuf-1.sentence-2)

The size of the state is
 the size of e's state plus k+1[.](#adapt.shuf-1.sentence-3)

[2](#adapt.shuf-2)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L3704)

The transition algorithm
permutes the values produced by e[.](#adapt.shuf-2.sentence-1)

The state transition is performed as follows:

- [(2.1)](#adapt.shuf-2.1)

  Calculate an integer j=âkâ(Yâemin)emaxâemin+1â [.](#adapt.shuf-2.1.sentence-1)

- [(2.2)](#adapt.shuf-2.2)

  Set Y to Vj and then set Vj to e()[.](#adapt.shuf-2.2.sentence-1)

[3](#adapt.shuf-3)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L3720)

The generation algorithm
yields the last value of Y produced while advancing e's state as described above[.](#adapt.shuf-3.sentence-1)

[ð](#lib:shuffle_order_engine_)

namespace std {template<class Engine, size_t k>class shuffle_order_engine {public:// typesusing result_type = typename Engine::result_type; // engine characteristicsstatic constexpr size_t table_size = k; static constexpr result_type min() { return Engine::min(); }static constexpr result_type max() { return Engine::max(); }// constructors and seeding functions shuffle_order_engine(); explicit shuffle_order_engine(const Engine& e); explicit shuffle_order_engine(Engine&& e); explicit shuffle_order_engine(result_type s); template<class Sseq> explicit shuffle_order_engine(Sseq& q); void seed(); void seed(result_type s); template<class Sseq> void seed(Sseq& q); // equality operatorsfriend bool operator==(const shuffle_order_engine& x, const shuffle_order_engine& y); // generating functions result_type operator()(); void discard(unsigned long long z); // property functionsconst Engine& base() const noexcept { return e; }// inserters and extractorstemplate<class charT, class traits>friend basic_ostream<charT, traits>&operator<<(basic_ostream<charT, traits>& os, const shuffle_order_engine& x); template<class charT, class traits>friend basic_istream<charT, traits>&operator>>(basic_istream<charT, traits>& is, shuffle_order_engine& x); private: Engine e; // *exposition only* result_type V[k]; // *exposition only* result_type Y; // *exposition only*};}

[4](#adapt.shuf-4)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L3776)

The following relation shall hold: 0 < k[.](#adapt.shuf-4.sentence-1)

[5](#adapt.shuf-5)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L3780)

The textual representation
consists of
 the textual representation of e,
followed by
 the k values of V,
followed by
 the value of Y[.](#adapt.shuf-5.sentence-1)

[6](#adapt.shuf-6)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L3789)

In addition to its behavior
pursuant to subclause [[rand.req.adapt]](#req.adapt "29.5.3.5 Random number engine adaptor requirements"),
each constructor that is not a copy constructor
initializes V[0], …, V[k - 1] and Y,
in that order,
with values returned by successive invocations of e()[.](#adapt.shuf-6.sentence-1)

### [29.5.6](#predef) Engines and engine adaptors with predefined parameters [[rand.predef]](rand.predef)

[ð](#lib:minstd_rand0)

`using minstd_rand0 =
      linear_congruential_engine<uint_fast32_t, 16'807, 0, 2'147'483'647>;
`

[1](#predef-1)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L3822)

*Required behavior*: The 10000th consecutive invocation
 of a default-constructed object
 of type minstd_rand0 produces the value 1043618065[.](#predef-1.sentence-1)

[ð](#lib:minstd_rand)

`using minstd_rand =
      linear_congruential_engine<uint_fast32_t, 48'271, 0, 2'147'483'647>;
`

[2](#predef-2)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L3837)

*Required behavior*: The 10000th consecutive invocation
 of a default-constructed object
 of type minstd_rand produces the value 399268537[.](#predef-2.sentence-1)

[ð](#lib:mt19937)

`using mt19937 =
      mersenne_twister_engine<uint_fast32_t, 32, 624, 397, 31,
       0x9908'b0df, 11, 0xffff'ffff, 7, 0x9d2c'5680, 15, 0xefc6'0000, 18, 1'812'433'253>;
`

[3](#predef-3)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L3853)

*Required behavior*: The 10000th consecutive invocation
 of a default-constructed object
 of type mt19937 produces the value 4123659995[.](#predef-3.sentence-1)

[ð](#lib:mt19937_64)

`using mt19937_64 =
      mersenne_twister_engine<uint_fast64_t, 64, 312, 156, 31,
       0xb502'6f5a'a966'19e9, 29, 0x5555'5555'5555'5555, 17,
       0x71d6'7fff'eda6'0000, 37, 0xfff7'eee0'0000'0000, 43, 6'364'136'223'846'793'005>;
`

[4](#predef-4)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L3870)

*Required behavior*: The 10000th consecutive invocation
 of a default-constructed object
 of type mt19937_64 produces the value 9981545732273789042[.](#predef-4.sentence-1)

[ð](#lib:ranlux24_base)

`using ranlux24_base =
      subtract_with_carry_engine<uint_fast32_t, 24, 10, 24>;
`

[5](#predef-5)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L3885)

*Required behavior*: The 10000th consecutive invocation
 of a default-constructed object
 of type ranlux24_base produces the value 7937952[.](#predef-5.sentence-1)

[ð](#lib:ranlux48_base)

`using ranlux48_base =
      subtract_with_carry_engine<uint_fast64_t, 48, 5, 12>;
`

[6](#predef-6)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L3901)

*Required behavior*: The 10000th consecutive invocation
 of a default-constructed object
 of type ranlux48_base produces the value 61839128582725[.](#predef-6.sentence-1)

[ð](#lib:ranlux24)

`using ranlux24 = discard_block_engine<ranlux24_base, 223, 23>;
`

[7](#predef-7)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L3916)

*Required behavior*: The 10000th consecutive invocation
 of a default-constructed object
 of type ranlux24 produces the value 9901578[.](#predef-7.sentence-1)

[ð](#lib:ranlux48)

`using ranlux48 = discard_block_engine<ranlux48_base, 389, 11>;
`

[8](#predef-8)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L3931)

*Required behavior*: The 10000th consecutive invocation
 of a default-constructed object
 of type ranlux48 produces the value 249142670248501[.](#predef-8.sentence-1)

[ð](#lib:knuth_b)

`using knuth_b = shuffle_order_engine<minstd_rand0,256>;
`

[9](#predef-9)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L3946)

*Required behavior*: The 10000th consecutive invocation
 of a default-constructed object
 of type knuth_b produces the value 1112339016[.](#predef-9.sentence-1)

[ð](#lib:default_random_engine)

`using default_random_engine = implementation-defined;
`

[10](#predef-10)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L3960)

*Remarks*: The choice of engine type
named by this typedef is implementation-defined[.](#predef-10.sentence-1)

[*Note [1](#predef-note-1)*:

The implementation
 can select this type
 on the basis of performance,
 size,
 quality,
 or any combination of such factors,
 so as to provide at least acceptable engine behavior
 for relatively casual, inexpert, and/or lightweight use[.](#predef-10.sentence-2)

Because different implementations
 can select different underlying engine types,
 code that uses this typedef need not generate identical sequences across implementations[.](#predef-10.sentence-3)

â *end note*]

[ð](#lib:philox4x32)

`using philox4x32 =
      philox_engine<uint_fast32_t, 32, 4, 10,
       0xCD9E8D57, 0x9E3779B9, 0xD2511F53, 0xBB67AE85>;
`

[11](#predef-11)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L3989)

*Required behavior*: The 10000th consecutive invocation
a default-constructed object of type philox4x32 produces the value 1955073260[.](#predef-11.sentence-1)

[ð](#lib:philox4x64)

`using philox4x64 =
      philox_engine<uint_fast64_t, 64, 4, 10,
       0xCA5A826395121157, 0x9E3779B97F4A7C15, 0xD2E7470EE14C6C93, 0xBB67AE8584CAA73B>;
`

[12](#predef-12)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L4004)

*Required behavior*: The 10000th consecutive invocation
a default-constructed object of type philox4x64 produces the value 3409172418970261260[.](#predef-12.sentence-1)

### [29.5.7](#device) Class random_device [[rand.device]](rand.device)

[1](#device-1)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L4027)

A random_device uniform random bit generator
produces nondeterministic random numbers[.](#device-1.sentence-1)

[2](#device-2)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L4032)

If implementation limitations
prevent generating nondeterministic random numbers,
the implementation may employ a random number engine[.](#device-2.sentence-1)

[ð](#lib:random_device_)

namespace std {class random_device {public:// typesusing result_type = unsigned int; // generator characteristicsstatic constexpr result_type min() { return numeric_limits<result_type>::min(); }static constexpr result_type max() { return numeric_limits<result_type>::max(); }// constructors random_device() : random_device(*implementation-defined*) {}explicit random_device(const string& token); // generating functions result_type operator()(); // property functionsdouble entropy() const noexcept; // no copy functions random_device(const random_device&) = delete; void operator=(const random_device&) = delete; };}

[ð](#lib:random_device,constructor)

`explicit random_device(const string& token);
`

[3](#device-3)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L4074)

*Throws*: A value of an implementation-defined type
 derived from exception if the random_device cannot be initialized[.](#device-3.sentence-1)

[4](#device-4)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L4080)

*Remarks*: The semantics of the token parameter
 and the token value used by the default constructor are implementation-defined[.](#device-4.sentence-1)[243](#footnote-243 "The parameter is intended to allow an implementation to differentiate between different sources of randomness.")

[ð](#lib:entropy,random_device)

`double entropy() const noexcept;
`

[5](#device-5)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L4098)

*Returns*: If the implementation employs a random number engine,
 returns 0.0[.](#device-5.sentence-1)

Otherwise, returns an entropy estimate[244](#footnote-244 "If a device has n states whose respective probabilities are ï¿½…ï¿½, the device entropy S is defined as S = - âï¿½.") for the random numbers returned by operator(),
 in the range min() to log2(max()+1)[.](#device-5.sentence-2)

[ð](#lib:operator(),random_device)

`result_type operator()();
`

[6](#device-6)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L4123)

*Returns*: A nondeterministic random value,
 uniformly distributed
 between min() and max() (inclusive)[.](#device-6.sentence-1)

It is implementation-defined
 how these values are generated[.](#device-6.sentence-2)

[7](#device-7)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L4131)

*Throws*: A value of an implementation-defined
 type derived from exception if a random number cannot be obtained[.](#device-7.sentence-1)

[243)](#footnote-243)[243)](#footnoteref-243)

The parameter is intended
 to allow an implementation to differentiate
 between different sources of randomness[.](#footnote-243.sentence-1)

[244)](#footnote-244)[244)](#footnoteref-244)

If a device has n states
 whose respective probabilities are P0,â¦,Pnâ1,
 the device entropy S is defined as  

S=âânâ1i=0PiâlogPi[.](#footnote-244.sentence-2)

### [29.5.8](#util) Utilities [[rand.util]](rand.util)

#### [29.5.8.1](#util.seedseq) Class seed_seq [[rand.util.seedseq]](rand.util.seedseq)

[ð](#lib:seed_seq)

namespace std {class seed_seq {public:// typesusing result_type = uint_least32_t; // constructors seed_seq() noexcept; template<class T> seed_seq(initializer_list<T> il); template<class InputIterator> seed_seq(InputIterator begin, InputIterator end); // generating functionstemplate<class RandomAccessIterator>void generate(RandomAccessIterator begin, RandomAccessIterator end); // property functions size_t size() const noexcept; template<class OutputIterator>void param(OutputIterator dest) const; // no copy functions seed_seq(const seed_seq&) = delete; void operator=(const seed_seq&) = delete; private: vector<result_type> v; // *exposition only*};}

[ð](#lib:seed_seq,constructor)

`seed_seq() noexcept;
`

[1](#util.seedseq-1)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L4198)

*Postconditions*: v.empty() is true[.](#util.seedseq-1.sentence-1)

[ð](#lib:seed_seq,constructor_)

`template<class T>
  seed_seq(initializer_list<T> il);
`

[2](#util.seedseq-2)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L4211)

*Constraints*: T is an integer type[.](#util.seedseq-2.sentence-1)

[3](#util.seedseq-3)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L4215)

*Effects*: Same as seed_seq(il.begin(), il.end())[.](#util.seedseq-3.sentence-1)

[ð](#lib:seed_seq,constructor__)

`template<class InputIterator>
  seed_seq(InputIterator begin, InputIterator end);
`

[4](#util.seedseq-4)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L4228)

*Mandates*: iterator_traits<InputIterator>​::​value_type is an integer type[.](#util.seedseq-4.sentence-1)

[5](#util.seedseq-5)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L4233)

*Preconditions*: InputIterator meets the [*Cpp17InputIterator*](input.iterators#:Cpp17InputIterator "24.3.5.3 Input iterators [input.iterators]") requirements ([[input.iterators]](input.iterators "24.3.5.3 Input iterators"))[.](#util.seedseq-5.sentence-1)

[6](#util.seedseq-6)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L4238)

*Effects*: Initializes v by the following algorithm:for (InputIterator s = begin; s != end; ++s) v.push_back((*s)mod232);

[ð](#lib:generate,seed_seq)

`template<class RandomAccessIterator>
  void generate(RandomAccessIterator begin, RandomAccessIterator end);
`

[7](#util.seedseq-7)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L4255)

*Mandates*: iterator_traits<RandomAccessIterator>​::​​value_type is an unsigned integer type capable of accommodating 32-bit quantities[.](#util.seedseq-7.sentence-1)

[8](#util.seedseq-8)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L4260)

*Preconditions*: RandomAccessIterator meets the [*Cpp17RandomAccessIterator*](random.access.iterators#:Cpp17RandomAccessIterator "24.3.5.7 Random access iterators [random.access.iterators]") requirements ([[random.access.iterators]](random.access.iterators "24.3.5.7 Random access iterators"))
 and the requirements of a mutable iterator[.](#util.seedseq-8.sentence-1)

[9](#util.seedseq-9)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L4266)

*Effects*: Does nothing if begin == end[.](#util.seedseq-9.sentence-1)

Otherwise,
 with s=v.size() and n=endâbegin,
 fills the supplied range [begin,end) according to the following algorithm
 in which
 each operation is to be carried out modulo 232,
 each indexing operator applied to begin is to be taken modulo n,
 and T(x) is defined as x xor(x rshift27):

- [(9.1)](#util.seedseq-9.1)

  By way of initialization,
 set each element of the range to the value 0x8b8b8b8b[.](#util.seedseq-9.1.sentence-1)
  Additionally,
 for use in subsequent steps,
 let p=(nât)/2 and let q=p+t,
 where   
t=(nâ¥623)Â ?Â 11Â :Â (nâ¥68)Â ?Â 7Â :Â (nâ¥39)Â ?Â 5Â :Â (nâ¥7)Â ?Â 3Â :Â (nâ1)/2;

- [(9.2)](#util.seedseq-9.2)

  With m as the larger of s+1 and n,
 transform the elements of the range:
 iteratively for k=0,â¦,mâ1,
 calculate values   
r1=1664525âT(begin[k]xorbegin[k+p]xorbegin[kâ1])r2=r1+â§âªâ¨âªâ©s,Â k=0kmodn+v[kâ1],Â 0<kâ¤skmodn,Â s<k and, in order,
 increment begin[k+p] by r1,
 increment begin[k+q] by r2,
 and
 set begin[k] to r2[.](#util.seedseq-9.2.sentence-1)

- [(9.3)](#util.seedseq-9.3)

  Transform the elements of the range again,
 beginning where the previous step ended:
 iteratively for k=m,â¦,m+nâ1,
 calculate values   
r3=1566083941âT(begin[k]+begin[k+p]+begin[kâ1])r4=r3â(kmodn) and, in order,
 update begin[k+p] by xoring it with r3,
 update begin[k+q] by xoring it with r4,
 and
 set begin[k] to r4[.](#util.seedseq-9.3.sentence-1)

[10](#util.seedseq-10)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L4339)

*Throws*: What and when RandomAccessIterator operations of begin and end throw[.](#util.seedseq-10.sentence-1)

[ð](#lib:size,seed_seq)

`size_t size() const noexcept;
`

[11](#util.seedseq-11)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L4351)

*Returns*: The number of 32-bit units
 that would be returned
 by a call to param()[.](#util.seedseq-11.sentence-1)

[12](#util.seedseq-12)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L4357)

*Complexity*: Constant time[.](#util.seedseq-12.sentence-1)

[ð](#lib:param,seed_seq)

`template<class OutputIterator>
  void param(OutputIterator dest) const;
`

[13](#util.seedseq-13)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L4369)

*Mandates*: Values of type result_type are writable ([[iterator.requirements.general]](iterator.requirements.general "24.3.1 General")) to dest[.](#util.seedseq-13.sentence-1)

[14](#util.seedseq-14)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L4373)

*Preconditions*: OutputIterator meets the [*Cpp17OutputIterator*](output.iterators#:Cpp17OutputIterator "24.3.5.4 Output iterators [output.iterators]") requirements ([[output.iterators]](output.iterators "24.3.5.4 Output iterators"))[.](#util.seedseq-14.sentence-1)

[15](#util.seedseq-15)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L4378)

*Effects*: Copies the sequence of prepared 32-bit units
 to the given destination,
 as if by executing the following statement:copy(v.begin(), v.end(), dest);

[16](#util.seedseq-16)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L4387)

*Throws*: What and when OutputIterator operations of dest throw[.](#util.seedseq-16.sentence-1)

#### [29.5.8.2](#util.canonical) Function template generate_canonical [[rand.util.canonical]](rand.util.canonical)

[ð](#lib:generate_canonical)

`template<class RealType, size_t digits, class URBG>
  RealType generate_canonical(URBG& g);
`

[1](#util.canonical-1)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L4404)

Let

- [(1.1)](#util.canonical-1.1)

r be numeric_limits<RealType>​::​radix,

- [(1.2)](#util.canonical-1.2)

R be g.max()âg.min()+1,

- [(1.3)](#util.canonical-1.3)

d be the smaller of digits and numeric_limits<RealType>​::​digits,[245](#footnote-245 "d is introduced to avoid any attempt to produce more bits of randomness than can be held in RealType.")

- [(1.4)](#util.canonical-1.4)

k be the smallest integer such that Rkâ¥rd, and

- [(1.5)](#util.canonical-1.5)

x be âRk/rdâ[.](#util.canonical-1.sentence-1)

An [*attempt*](#def:attempt "29.5.8.2 Function template generate_­canonical [rand.util.canonical]") is k invocations of g() to obtain values g0,â¦,gkâ1, respectively,
and the calculation of a quantity S given by Formula [29.1](#eq:rand.gencanonical):

S=kâ1âi=0(giâg.min())âRi(29.1)

[2](#util.canonical-2)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L4426)

*Effects*: Attempts are made until S<xrd[.](#util.canonical-2.sentence-1)

[*Note [1](#util.canonical-note-1)*:

When R is a power of r, precisely one attempt is made[.](#util.canonical-2.sentence-2)

â *end note*]

[3](#util.canonical-3)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L4433)

*Returns*: âS/xâ/rd[.](#util.canonical-3.sentence-1)

[*Note [2](#util.canonical-note-2)*:

The return value c satisfies0â¤c<1[.](#util.canonical-3.sentence-2)

â *end note*]

[4](#util.canonical-4)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L4441)

*Throws*: What and when g throws[.](#util.canonical-4.sentence-1)

[5](#util.canonical-5)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L4445)

*Complexity*: Exactly k invocations of g per attempt[.](#util.canonical-5.sentence-1)

[6](#util.canonical-6)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L4449)

[*Note [3](#util.canonical-note-3)*:

If the values gi produced by g are uniformly distributed,
the instantiation's results are distributed as uniformly as possible[.](#util.canonical-6.sentence-1)

Obtaining a value in this way
can be a useful step
in the process of transforming
a value generated by a uniform random bit generator
into a value
that can be delivered by a random number distribution[.](#util.canonical-6.sentence-2)

â *end note*]

[7](#util.canonical-7)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L4461)

[*Note [4](#util.canonical-note-4)*:

When R is a power of r,
an implementation can avoid using an arithmetic type that is wider
than the output when computing S[.](#util.canonical-7.sentence-1)

â *end note*]

[245)](#footnote-245)[245)](#footnoteref-245)

d is introduced to avoid any attempt
 to produce more bits of randomness
 than can be held in RealType[.](#footnote-245.sentence-1)

### [29.5.9](#dist) Random number distribution class templates [[rand.dist]](rand.dist)

#### [29.5.9.1](#dist.general) General [[rand.dist.general]](rand.dist.general)

[1](#dist.general-1)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L4486)

Each type instantiated
from a class template specified in [[rand.dist]](#dist "29.5.9 Random number distribution class templates") meets the requirements
of a [random number distribution](#req.dist "29.5.3.6 Random number distribution requirements [rand.req.dist]") type[.](#dist.general-1.sentence-1)

[2](#dist.general-2)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L4492)

Descriptions are provided in [[rand.dist]](#dist "29.5.9 Random number distribution class templates") only for distribution operations
that are not described in [[rand.req.dist]](#req.dist "29.5.3.6 Random number distribution requirements") or for operations where there is additional semantic information[.](#dist.general-2.sentence-1)

In particular,
declarations for copy constructors,
for copy assignment operators,
for streaming operators,
and for equality and inequality operators
are not shown in the synopses[.](#dist.general-2.sentence-2)

[3](#dist.general-3)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L4504)

The algorithms for producing each
of the specified distributions areimplementation-defined[.](#dist.general-3.sentence-1)

[4](#dist.general-4)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L4509)

The value of each probability density function p(z) and of each discrete probability function P(zi) specified in this subclause
is 0 everywhere outside its stated domain[.](#dist.general-4.sentence-1)

#### [29.5.9.2](#dist.uni) Uniform distributions [[rand.dist.uni]](rand.dist.uni)

#### [29.5.9.2.1](#dist.uni.int) Class template uniform_int_distribution [[rand.dist.uni.int]](rand.dist.uni.int)

[1](#dist.uni.int-1)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L4532)

A uniform_int_distribution random number distribution
produces random integers i,a â¤ i â¤ b,
distributed according to
the constant discrete probability function in Formula [29.2](#eq:rand.dist.uni.int)[.](#dist.uni.int-1.sentence-1)

P(i|a,b)=1/(bâa+1)(29.2)

[ð](#lib:uniform_int_distribution_)

namespace std {template<class IntType = int>class uniform_int_distribution {public:// typesusing result_type = IntType; using param_type = *unspecified*; // constructors and reset functions uniform_int_distribution() : uniform_int_distribution(0) {}explicit uniform_int_distribution(IntType a, IntType b = numeric_limits<IntType>::max()); explicit uniform_int_distribution(const param_type& parm); void reset(); // equality operatorsfriend bool operator==(const uniform_int_distribution& x, const uniform_int_distribution& y); // generating functionstemplate<class URBG> result_type operator()(URBG& g); template<class URBG> result_type operator()(URBG& g, const param_type& parm); // property functions result_type a() const;
 result_type b() const;
 param_type param() const; void param(const param_type& parm);
 result_type min() const;
 result_type max() const; // inserters and extractorstemplate<class charT, class traits>friend basic_ostream<charT, traits>&operator<<(basic_ostream<charT, traits>& os, // hostedconst uniform_int_distribution& x); template<class charT, class traits>friend basic_istream<charT, traits>&operator>>(basic_istream<charT, traits>& is, // hosted uniform_int_distribution& x); };}

[ð](#lib:uniform_int_distribution,constructor)

`explicit uniform_int_distribution(IntType a, IntType b = numeric_limits<IntType>::max());
`

[2](#dist.uni.int-2)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L4597)

*Preconditions*: a â¤ b[.](#dist.uni.int-2.sentence-1)

[3](#dist.uni.int-3)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L4601)

*Remarks*: a and b correspond to the respective parameters of the distribution[.](#dist.uni.int-3.sentence-1)

[ð](#lib:a,uniform_int_distribution)

`result_type a() const;
`

[4](#dist.uni.int-4)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L4613)

*Returns*: The value of the a parameter
 with which the object was constructed[.](#dist.uni.int-4.sentence-1)

[ð](#lib:b,uniform_int_distribution)

`result_type b() const;
`

[5](#dist.uni.int-5)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L4625)

*Returns*: The value of the b parameter
 with which the object was constructed[.](#dist.uni.int-5.sentence-1)

#### [29.5.9.2.2](#dist.uni.real) Class template uniform_real_distribution [[rand.dist.uni.real]](rand.dist.uni.real)

[1](#dist.uni.real-1)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L4637)

A uniform_real_distribution random number distribution
produces random numbers x,aâ¤x<b,
distributed according to
the constant probability density function in Formula [29.3](#eq:rand.dist.uni.real)[.](#dist.uni.real-1.sentence-1)

p(x|a,b)=1/(bâa)(29.3)

[*Note [1](#dist.uni.real-note-1)*:

This implies that p(x | a,b) is undefined when a == b[.](#dist.uni.real-1.sentence-2)

â *end note*]

[ð](#lib:uniform_real_distribution_)

namespace std {template<class RealType = double>class uniform_real_distribution {public:// typesusing result_type = RealType; using param_type = *unspecified*; // constructors and reset functions uniform_real_distribution() : uniform_real_distribution(0.0) {}explicit uniform_real_distribution(RealType a, RealType b = 1.0); explicit uniform_real_distribution(const param_type& parm); void reset(); // equality operatorsfriend bool operator==(const uniform_real_distribution& x, const uniform_real_distribution& y); // generating functionstemplate<class URBG> result_type operator()(URBG& g); template<class URBG> result_type operator()(URBG& g, const param_type& parm); // property functions result_type a() const;
 result_type b() const;
 param_type param() const; void param(const param_type& parm);
 result_type min() const;
 result_type max() const; // inserters and extractorstemplate<class charT, class traits>friend basic_ostream<charT, traits>&operator<<(basic_ostream<charT, traits>& os, const uniform_real_distribution& x); template<class charT, class traits>friend basic_istream<charT, traits>&operator>>(basic_istream<charT, traits>& is, uniform_real_distribution& x); };}

[ð](#lib:uniform_real_distribution,constructor)

`explicit uniform_real_distribution(RealType a, RealType b = 1.0);
`

[2](#dist.uni.real-2)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L4703)

*Preconditions*: a â¤ b andbâaâ¤numeric_limits<RealType>::max()[.](#dist.uni.real-2.sentence-1)

[3](#dist.uni.real-3)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L4709)

*Remarks*: a and b correspond to the respective parameters of the distribution[.](#dist.uni.real-3.sentence-1)

[ð](#lib:a,uniform_real_distribution)

`result_type a() const;
`

[4](#dist.uni.real-4)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L4721)

*Returns*: The value of the a parameter
 with which the object was constructed[.](#dist.uni.real-4.sentence-1)

[ð](#lib:b,uniform_real_distribution)

`result_type b() const;
`

[5](#dist.uni.real-5)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L4733)

*Returns*: The value of the b parameter
 with which the object was constructed[.](#dist.uni.real-5.sentence-1)

#### [29.5.9.3](#dist.bern) Bernoulli distributions [[rand.dist.bern]](rand.dist.bern)

#### [29.5.9.3.1](#dist.bern.bernoulli) Class bernoulli_distribution [[rand.dist.bern.bernoulli]](rand.dist.bern.bernoulli)

[1](#dist.bern.bernoulli-1)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L4758)

A bernoulli_distribution random number distribution
produces bool values b distributed according to
the discrete probability function in Formula [29.4](#eq:rand.dist.bern.bernoulli)[.](#dist.bern.bernoulli-1.sentence-1)

P(b|p)={pÂ ifÂ b=true1âpÂ ifÂ b=false(29.4)

[ð](#lib:bernoulli_distribution_)

namespace std {class bernoulli_distribution {public:// typesusing result_type = bool; using param_type = *unspecified*; // constructors and reset functions bernoulli_distribution() : bernoulli_distribution(0.5) {}explicit bernoulli_distribution(double p); explicit bernoulli_distribution(const param_type& parm); void reset(); // equality operatorsfriend bool operator==(const bernoulli_distribution& x, const bernoulli_distribution& y); // generating functionstemplate<class URBG> result_type operator()(URBG& g); template<class URBG> result_type operator()(URBG& g, const param_type& parm); // property functionsdouble p() const;
 param_type param() const; void param(const param_type& parm);
 result_type min() const;
 result_type max() const; // inserters and extractorstemplate<class charT, class traits>friend basic_ostream<charT, traits>&operator<<(basic_ostream<charT, traits>& os, const bernoulli_distribution& x); template<class charT, class traits>friend basic_istream<charT, traits>&operator>>(basic_istream<charT, traits>& is, bernoulli_distribution& x); };}

[ð](#lib:bernoulli_distribution,constructor)

`explicit bernoulli_distribution(double p);
`

[2](#dist.bern.bernoulli-2)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L4820)

*Preconditions*: 0 â¤ p â¤ 1[.](#dist.bern.bernoulli-2.sentence-1)

[3](#dist.bern.bernoulli-3)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L4824)

*Remarks*: p corresponds to the parameter of the distribution[.](#dist.bern.bernoulli-3.sentence-1)

[ð](#lib:p,bernoulli_distribution)

`double p() const;
`

[4](#dist.bern.bernoulli-4)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L4836)

*Returns*: The value of the p parameter
 with which the object was constructed[.](#dist.bern.bernoulli-4.sentence-1)

#### [29.5.9.3.2](#dist.bern.bin) Class template binomial_distribution [[rand.dist.bern.bin]](rand.dist.bern.bin)

[1](#dist.bern.bin-1)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L4848)

A binomial_distribution random number distribution
produces integer values i â¥ 0 distributed according to
the discrete probability function in Formula [29.5](#eq:rand.dist.bern.bin)[.](#dist.bern.bin-1.sentence-1)

P(i|t,p)=(ti)âpiâ(1âp)tâi(29.5)

[ð](#lib:binomial_distribution_)

namespace std {template<class IntType = int>class binomial_distribution {public:// typesusing result_type = IntType; using param_type = *unspecified*; // constructors and reset functions binomial_distribution() : binomial_distribution(1) {}explicit binomial_distribution(IntType t, double p = 0.5); explicit binomial_distribution(const param_type& parm); void reset(); // equality operatorsfriend bool operator==(const binomial_distribution& x, const binomial_distribution& y); // generating functionstemplate<class URBG> result_type operator()(URBG& g); template<class URBG> result_type operator()(URBG& g, const param_type& parm); // property functions IntType t() const; double p() const;
 param_type param() const; void param(const param_type& parm);
 result_type min() const;
 result_type max() const; // inserters and extractorstemplate<class charT, class traits>friend basic_ostream<charT, traits>&operator<<(basic_ostream<charT, traits>& os, const binomial_distribution& x); template<class charT, class traits>friend basic_istream<charT, traits>&operator>>(basic_istream<charT, traits>& is, binomial_distribution& x); };}

[ð](#lib:binomial_distribution,constructor)

`explicit binomial_distribution(IntType t, double p = 0.5);
`

[2](#dist.bern.bin-2)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L4910)

*Preconditions*: 0 â¤ p â¤ 1 and 0 â¤ t[.](#dist.bern.bin-2.sentence-1)

[3](#dist.bern.bin-3)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L4914)

*Remarks*: t and p correspond to the respective parameters of the distribution[.](#dist.bern.bin-3.sentence-1)

[ð](#lib:t,binomial_distribution)

`IntType t() const;
`

[4](#dist.bern.bin-4)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L4925)

*Returns*: The value of the t parameter
 with which the object was constructed[.](#dist.bern.bin-4.sentence-1)

[ð](#lib:p,binomial_distribution)

`double p() const;
`

[5](#dist.bern.bin-5)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L4937)

*Returns*: The value of the p parameter
 with which the object was constructed[.](#dist.bern.bin-5.sentence-1)

#### [29.5.9.3.3](#dist.bern.geo) Class template geometric_distribution [[rand.dist.bern.geo]](rand.dist.bern.geo)

[1](#dist.bern.geo-1)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L4949)

A geometric_distribution random number distribution
produces integer values i â¥ 0 distributed according to
the discrete probability function in Formula [29.6](#eq:rand.dist.bern.geo)[.](#dist.bern.geo-1.sentence-1)

P(i|p)=pâ(1âp)i(29.6)

[ð](#lib:geometric_distribution_)

namespace std {template<class IntType = int>class geometric_distribution {public:// typesusing result_type = IntType; using param_type = *unspecified*; // constructors and reset functions geometric_distribution() : geometric_distribution(0.5) {}explicit geometric_distribution(double p); explicit geometric_distribution(const param_type& parm); void reset(); // equality operatorsfriend bool operator==(const geometric_distribution& x, const geometric_distribution& y); // generating functionstemplate<class URBG> result_type operator()(URBG& g); template<class URBG> result_type operator()(URBG& g, const param_type& parm); // property functionsdouble p() const;
 param_type param() const; void param(const param_type& parm);
 result_type min() const;
 result_type max() const; // inserters and extractorstemplate<class charT, class traits>friend basic_ostream<charT, traits>&operator<<(basic_ostream<charT, traits>& os, const geometric_distribution& x); template<class charT, class traits>friend basic_istream<charT, traits>&operator>>(basic_istream<charT, traits>& is, geometric_distribution& x); };}

[ð](#lib:geometric_distribution,constructor)

`explicit geometric_distribution(double p);
`

[2](#dist.bern.geo-2)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L5009)

*Preconditions*: 0<p<1[.](#dist.bern.geo-2.sentence-1)

[3](#dist.bern.geo-3)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L5013)

*Remarks*: p corresponds to the parameter of the distribution[.](#dist.bern.geo-3.sentence-1)

[ð](#lib:p,geometric_distribution)

`double p() const;
`

[4](#dist.bern.geo-4)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L5025)

*Returns*: The value of the p parameter
 with which the object was constructed[.](#dist.bern.geo-4.sentence-1)

#### [29.5.9.3.4](#dist.bern.negbin) Class template negative_binomial_distribution [[rand.dist.bern.negbin]](rand.dist.bern.negbin)

[1](#dist.bern.negbin-1)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L5038)

A negative_binomial_distribution random number distribution
produces random integers i â¥ 0 distributed according to
the discrete probability function in Formula [29.7](#eq:rand.dist.bern.negbin)[.](#dist.bern.negbin-1.sentence-1)

P(i|k,p)=(k+iâ1i)âpkâ(1âp)i(29.7)

[*Note [1](#dist.bern.negbin-note-1)*:

This implies that P(i | k,p) is undefined when p == 1[.](#dist.bern.negbin-1.sentence-2)

â *end note*]

[ð](#lib:negative_binomial_distribution_)

namespace std {template<class IntType = int>class negative_binomial_distribution {public:// typesusing result_type = IntType; using param_type = *unspecified*; // constructor and reset functions negative_binomial_distribution() : negative_binomial_distribution(1) {}explicit negative_binomial_distribution(IntType k, double p = 0.5); explicit negative_binomial_distribution(const param_type& parm); void reset(); // equality operatorsfriend bool operator==(const negative_binomial_distribution& x, const negative_binomial_distribution& y); // generating functionstemplate<class URBG> result_type operator()(URBG& g); template<class URBG> result_type operator()(URBG& g, const param_type& parm); // property functions IntType k() const; double p() const;
 param_type param() const; void param(const param_type& parm);
 result_type min() const;
 result_type max() const; // inserters and extractorstemplate<class charT, class traits>friend basic_ostream<charT, traits>&operator<<(basic_ostream<charT, traits>& os, const negative_binomial_distribution& x); template<class charT, class traits>friend basic_istream<charT, traits>&operator>>(basic_istream<charT, traits>& is, negative_binomial_distribution& x); };}

[ð](#lib:negative_binomial_distribution,constructor)

`explicit negative_binomial_distribution(IntType k, double p = 0.5);
`

[2](#dist.bern.negbin-2)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L5103)

*Preconditions*: 0<pâ¤1 and 0<k[.](#dist.bern.negbin-2.sentence-1)

[3](#dist.bern.negbin-3)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L5108)

*Remarks*: k and p correspond to the respective parameters of the distribution[.](#dist.bern.negbin-3.sentence-1)

[ð](#lib:k,negative_binomial_distribution)

`IntType k() const;
`

[4](#dist.bern.negbin-4)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L5120)

*Returns*: The value of the k parameter
 with which the object was constructed[.](#dist.bern.negbin-4.sentence-1)

[ð](#lib:p,negative_binomial_distribution)

`double p() const;
`

[5](#dist.bern.negbin-5)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L5132)

*Returns*: The value of the p parameter
 with which the object was constructed[.](#dist.bern.negbin-5.sentence-1)

#### [29.5.9.4](#dist.pois) Poisson distributions [[rand.dist.pois]](rand.dist.pois)

#### [29.5.9.4.1](#dist.pois.poisson) Class template poisson_distribution [[rand.dist.pois.poisson]](rand.dist.pois.poisson)

[1](#dist.pois.poisson-1)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L5157)

A poisson_distribution random number distribution
produces integer values i â¥ 0 distributed according to
the discrete probability function in Formula [29.8](#eq:rand.dist.pois.poisson)[.](#dist.pois.poisson-1.sentence-1)

P(i|Î¼)=eâÎ¼Î¼ii!(29.8)

The distribution parameter Î¼ is also known as this distribution's [*mean*](#def:mean)[.](#dist.pois.poisson-1.sentence-2)

[ð](#lib:poisson_distribution_)

namespace std {template<class IntType = int>class poisson_distribution {public:// typesusing result_type = IntType; using param_type = *unspecified*; // constructors and reset functions poisson_distribution() : poisson_distribution(1.0) {}explicit poisson_distribution(double mean); explicit poisson_distribution(const param_type& parm); void reset(); // equality operatorsfriend bool operator==(const poisson_distribution& x, const poisson_distribution& y); // generating functionstemplate<class URBG> result_type operator()(URBG& g); template<class URBG> result_type operator()(URBG& g, const param_type& parm); // property functionsdouble mean() const;
 param_type param() const; void param(const param_type& parm);
 result_type min() const;
 result_type max() const; // inserters and extractorstemplate<class charT, class traits>friend basic_ostream<charT, traits>&operator<<(basic_ostream<charT, traits>& os, const poisson_distribution& x); template<class charT, class traits>friend basic_istream<charT, traits>&operator>>(basic_istream<charT, traits>& is, poisson_distribution& x); };}

[ð](#lib:poisson_distribution,constructor)

`explicit poisson_distribution(double mean);
`

[2](#dist.pois.poisson-2)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L5218)

*Preconditions*: 0<mean[.](#dist.pois.poisson-2.sentence-1)

[3](#dist.pois.poisson-3)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L5222)

*Remarks*: mean corresponds to the parameter of the distribution[.](#dist.pois.poisson-3.sentence-1)

[ð](#lib:mean,poisson_distribution)

`double mean() const;
`

[4](#dist.pois.poisson-4)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L5233)

*Returns*: The value of the mean parameter
 with which the object was constructed[.](#dist.pois.poisson-4.sentence-1)

#### [29.5.9.4.2](#dist.pois.exp) Class template exponential_distribution [[rand.dist.pois.exp]](rand.dist.pois.exp)

[1](#dist.pois.exp-1)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L5245)

An exponential_distribution random number distribution
produces random numbers x>0 distributed according to
the probability density function in Formula [29.9](#eq:rand.dist.pois.exp)[.](#dist.pois.exp-1.sentence-1)

p(x|Î»)=Î»eâÎ»x(29.9)

[ð](#lib:exponential_distribution_)

namespace std {template<class RealType = double>class exponential_distribution {public:// typesusing result_type = RealType; using param_type = *unspecified*; // constructors and reset functions exponential_distribution() : exponential_distribution(1.0) {}explicit exponential_distribution(RealType lambda); explicit exponential_distribution(const param_type& parm); void reset(); // equality operatorsfriend bool operator==(const exponential_distribution& x, const exponential_distribution& y); // generating functionstemplate<class URBG> result_type operator()(URBG& g); template<class URBG> result_type operator()(URBG& g, const param_type& parm); // property functions RealType lambda() const;
 param_type param() const; void param(const param_type& parm);
 result_type min() const;
 result_type max() const; // inserters and extractorstemplate<class charT, class traits>friend basic_ostream<charT, traits>&operator<<(basic_ostream<charT, traits>& os, const exponential_distribution& x); template<class charT, class traits>friend basic_istream<charT, traits>&operator>>(basic_istream<charT, traits>& is, exponential_distribution& x); };}

[ð](#lib:exponential_distribution,constructor)

`explicit exponential_distribution(RealType lambda);
`

[2](#dist.pois.exp-2)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L5305)

*Preconditions*: 0<lambda[.](#dist.pois.exp-2.sentence-1)

[3](#dist.pois.exp-3)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L5309)

*Remarks*: lambda corresponds to the parameter of the distribution[.](#dist.pois.exp-3.sentence-1)

[ð](#lib:lambda,exponential_distribution)

`RealType lambda() const;
`

[4](#dist.pois.exp-4)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L5320)

*Returns*: The value of the lambda parameter
 with which the object was constructed[.](#dist.pois.exp-4.sentence-1)

#### [29.5.9.4.3](#dist.pois.gamma) Class template gamma_distribution [[rand.dist.pois.gamma]](rand.dist.pois.gamma)

[1](#dist.pois.gamma-1)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L5332)

A gamma_distribution random number distribution
produces random numbers x>0 distributed according to
the probability density function in Formula [29.10](#eq:rand.dist.pois.gamma)[.](#dist.pois.gamma-1.sentence-1)

p(x|Î±,Î²)=eâx/Î²Î²Î±âÎ(Î±)âxÎ±â1(29.10)

[ð](#lib:gamma_distribution_)

namespace std {template<class RealType = double>class gamma_distribution {public:// typesusing result_type = RealType; using param_type = *unspecified*; // constructors and reset functions gamma_distribution() : gamma_distribution(1.0) {}explicit gamma_distribution(RealType alpha, RealType beta = 1.0); explicit gamma_distribution(const param_type& parm); void reset(); // equality operatorsfriend bool operator==(const gamma_distribution& x, const gamma_distribution& y); // generating functionstemplate<class URBG> result_type operator()(URBG& g); template<class URBG> result_type operator()(URBG& g, const param_type& parm); // property functions RealType alpha() const;
 RealType beta() const;
 param_type param() const; void param(const param_type& parm);
 result_type min() const;
 result_type max() const; // inserters and extractorstemplate<class charT, class traits>friend basic_ostream<charT, traits>&operator<<(basic_ostream<charT, traits>& os, const gamma_distribution& x); template<class charT, class traits>friend basic_istream<charT, traits>&operator>>(basic_istream<charT, traits>& is, gamma_distribution& x); };}

[ð](#lib:gamma_distribution,constructor)

`explicit gamma_distribution(RealType alpha, RealType beta = 1.0);
`

[2](#dist.pois.gamma-2)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L5394)

*Preconditions*: 0<alpha and 0<beta[.](#dist.pois.gamma-2.sentence-1)

[3](#dist.pois.gamma-3)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L5398)

*Remarks*: alpha and beta correspond to the parameters of the distribution[.](#dist.pois.gamma-3.sentence-1)

[ð](#lib:alpha,gamma_distribution)

`RealType alpha() const;
`

[4](#dist.pois.gamma-4)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L5410)

*Returns*: The value of the alpha parameter
 with which the object was constructed[.](#dist.pois.gamma-4.sentence-1)

[ð](#lib:beta,gamma_distribution)

`RealType beta() const;
`

[5](#dist.pois.gamma-5)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L5422)

*Returns*: The value of the beta parameter
 with which the object was constructed[.](#dist.pois.gamma-5.sentence-1)

#### [29.5.9.4.4](#dist.pois.weibull) Class template weibull_distribution [[rand.dist.pois.weibull]](rand.dist.pois.weibull)

[1](#dist.pois.weibull-1)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L5435)

A weibull_distribution random number distribution
produces random numbers x â¥ 0 distributed according to
the probability density function in Formula [29.11](#eq:rand.dist.pois.weibull)[.](#dist.pois.weibull-1.sentence-1)

p(x|a,b)=abâ(xb)aâ1âexp(â(xb)a)(29.11)

[ð](#lib:weibull_distribution_)

namespace std {template<class RealType = double>class weibull_distribution {public:// typesusing result_type = RealType; using param_type = *unspecified*; // constructor and reset functions weibull_distribution() : weibull_distribution(1.0) {}explicit weibull_distribution(RealType a, RealType b = 1.0); explicit weibull_distribution(const param_type& parm); void reset(); // equality operatorsfriend bool operator==(const weibull_distribution& x, const weibull_distribution& y); // generating functionstemplate<class URBG> result_type operator()(URBG& g); template<class URBG> result_type operator()(URBG& g, const param_type& parm); // property functions RealType a() const;
 RealType b() const;
 param_type param() const; void param(const param_type& parm);
 result_type min() const;
 result_type max() const; // inserters and extractorstemplate<class charT, class traits>friend basic_ostream<charT, traits>&operator<<(basic_ostream<charT, traits>& os, const weibull_distribution& x); template<class charT, class traits>friend basic_istream<charT, traits>&operator>>(basic_istream<charT, traits>& is, weibull_distribution& x); };}

[ð](#lib:weibull_distribution,constructor)

`explicit weibull_distribution(RealType a, RealType b = 1.0);
`

[2](#dist.pois.weibull-2)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L5497)

*Preconditions*: 0<a and 0<b[.](#dist.pois.weibull-2.sentence-1)

[3](#dist.pois.weibull-3)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L5501)

*Remarks*: a and b correspond to the respective parameters of the distribution[.](#dist.pois.weibull-3.sentence-1)

[ð](#lib:a,weibull_distribution)

`RealType a() const;
`

[4](#dist.pois.weibull-4)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L5513)

*Returns*: The value of the a parameter
 with which the object was constructed[.](#dist.pois.weibull-4.sentence-1)

[ð](#lib:b,weibull_distribution)

`RealType b() const;
`

[5](#dist.pois.weibull-5)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L5525)

*Returns*: The value of the b parameter
 with which the object was constructed[.](#dist.pois.weibull-5.sentence-1)

#### [29.5.9.4.5](#dist.pois.extreme) Class template extreme_value_distribution [[rand.dist.pois.extreme]](rand.dist.pois.extreme)

[1](#dist.pois.extreme-1)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L5538)

An extreme_value_distribution random number distribution
produces random numbers x distributed according to
the probability density function in Formula [29.12](#eq:rand.dist.pois.extreme)[.](#dist.pois.extreme-1.sentence-1)[246](#footnote-246 "The distribution corresponding to this probability density function is also known (with a possible change of variable) as the Gumbel Type I, the log-Weibull, or the Fisher-Tippett Type I distribution.")

p(x|a,b)=1bâexp(aâxbâexp(aâxb))(29.12)

[ð](#lib:extreme_value_distribution_)

namespace std {template<class RealType = double>class extreme_value_distribution {public:// typesusing result_type = RealType; using param_type = *unspecified*; // constructor and reset functions extreme_value_distribution() : extreme_value_distribution(0.0) {}explicit extreme_value_distribution(RealType a, RealType b = 1.0); explicit extreme_value_distribution(const param_type& parm); void reset(); // equality operatorsfriend bool operator==(const extreme_value_distribution& x, const extreme_value_distribution& y); // generating functionstemplate<class URBG> result_type operator()(URBG& g); template<class URBG> result_type operator()(URBG& g, const param_type& parm); // property functions RealType a() const;
 RealType b() const;
 param_type param() const; void param(const param_type& parm);
 result_type min() const;
 result_type max() const; // inserters and extractorstemplate<class charT, class traits>friend basic_ostream<charT, traits>&operator<<(basic_ostream<charT, traits>& os, const extreme_value_distribution& x); template<class charT, class traits>friend basic_istream<charT, traits>&operator>>(basic_istream<charT, traits>& is, extreme_value_distribution& x); };}

[ð](#lib:extreme_value_distribution,constructor)

`explicit extreme_value_distribution(RealType a, RealType b = 1.0);
`

[2](#dist.pois.extreme-2)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L5610)

*Preconditions*: 0<b[.](#dist.pois.extreme-2.sentence-1)

[3](#dist.pois.extreme-3)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L5614)

*Remarks*: a and b correspond to the respective parameters of the distribution[.](#dist.pois.extreme-3.sentence-1)

[ð](#lib:a,extreme_value_distribution)

`RealType a() const;
`

[4](#dist.pois.extreme-4)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L5626)

*Returns*: The value of the a parameter
 with which the object was constructed[.](#dist.pois.extreme-4.sentence-1)

[ð](#lib:b,extreme_value_distribution)

`RealType b() const;
`

[5](#dist.pois.extreme-5)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L5638)

*Returns*: The value of the b parameter
 with which the object was constructed[.](#dist.pois.extreme-5.sentence-1)

[246)](#footnote-246)[246)](#footnoteref-246)

The distribution corresponding to
 this probability density function
 is also known
 (with a possible change of variable)
 as the Gumbel Type I,
 the log-Weibull,
 or the Fisher-Tippett Type I
 distribution[.](#footnote-246.sentence-1)

#### [29.5.9.5](#dist.norm) Normal distributions [[rand.dist.norm]](rand.dist.norm)

#### [29.5.9.5.1](#dist.norm.normal) Class template normal_distribution [[rand.dist.norm.normal]](rand.dist.norm.normal)

[1](#dist.norm.normal-1)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L5663)

A normal_distribution random number distribution
produces random numbers x distributed according to
the probability density function in Formula [29.13](#eq:rand.dist.norm.normal)[.](#dist.norm.normal-1.sentence-1)

p(x|Î¼,Ï)=1Ïâ2Ïâexp(â(xâÎ¼)22Ï2)(29.13)

The distribution parameters Î¼ and Ï are also known as this distribution's [*mean*](#def:mean) and [*standard deviation*](#def:standard_deviation)[.](#dist.norm.normal-1.sentence-2)

[ð](#lib:normal_distribution_)

namespace std {template<class RealType = double>class normal_distribution {public:// typesusing result_type = RealType; using param_type = *unspecified*; // constructors and reset functions normal_distribution() : normal_distribution(0.0) {}explicit normal_distribution(RealType mean, RealType stddev = 1.0); explicit normal_distribution(const param_type& parm); void reset(); // equality operatorsfriend bool operator==(const normal_distribution& x, const normal_distribution& y); // generating functionstemplate<class URBG> result_type operator()(URBG& g); template<class URBG> result_type operator()(URBG& g, const param_type& parm); // property functions RealType mean() const;
 RealType stddev() const;
 param_type param() const; void param(const param_type& parm);
 result_type min() const;
 result_type max() const; // inserters and extractorstemplate<class charT, class traits>friend basic_ostream<charT, traits>&operator<<(basic_ostream<charT, traits>& os, const normal_distribution& x); template<class charT, class traits>friend basic_istream<charT, traits>&operator>>(basic_istream<charT, traits>& is, normal_distribution& x); };}

[ð](#lib:normal_distribution,constructor)

`explicit normal_distribution(RealType mean, RealType stddev = 1.0);
`

[2](#dist.norm.normal-2)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L5733)

*Preconditions*: 0<stddev[.](#dist.norm.normal-2.sentence-1)

[3](#dist.norm.normal-3)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L5737)

*Remarks*: mean and stddev correspond to the respective parameters of the distribution[.](#dist.norm.normal-3.sentence-1)

[ð](#lib:mean,normal_distribution)

`RealType mean() const;
`

[4](#dist.norm.normal-4)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L5749)

*Returns*: The value of the mean parameter
 with which the object was constructed[.](#dist.norm.normal-4.sentence-1)

[ð](#lib:stddev,normal_distribution)

`RealType stddev() const;
`

[5](#dist.norm.normal-5)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L5761)

*Returns*: The value of the stddev parameter
 with which the object was constructed[.](#dist.norm.normal-5.sentence-1)

#### [29.5.9.5.2](#dist.norm.lognormal) Class template lognormal_distribution [[rand.dist.norm.lognormal]](rand.dist.norm.lognormal)

[1](#dist.norm.lognormal-1)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L5774)

A lognormal_distribution random number distribution
produces random numbers x>0 distributed according to
the probability density function in Formula [29.14](#eq:rand.dist.norm.lognormal)[.](#dist.norm.lognormal-1.sentence-1)

p(x|m,s)=1sxâ2Ïâexp(â(lnxâm)22s2)(29.14)

[ð](#lib:lognormal_distribution_)

namespace std {template<class RealType = double>class lognormal_distribution {public:// typesusing result_type = RealType; using param_type = *unspecified*; // constructor and reset functions lognormal_distribution() : lognormal_distribution(0.0) {}explicit lognormal_distribution(RealType m, RealType s = 1.0); explicit lognormal_distribution(const param_type& parm); void reset(); // equality operatorsfriend bool operator==(const lognormal_distribution& x, const lognormal_distribution& y); // generating functionstemplate<class URBG> result_type operator()(URBG& g); template<class URBG> result_type operator()(URBG& g, const param_type& parm); // property functions RealType m() const;
 RealType s() const;
 param_type param() const; void param(const param_type& parm);
 result_type min() const;
 result_type max() const; // inserters and extractorstemplate<class charT, class traits>friend basic_ostream<charT, traits>&operator<<(basic_ostream<charT, traits>& os, const lognormal_distribution& x); template<class charT, class traits>friend basic_istream<charT, traits>&operator>>(basic_istream<charT, traits>& is, lognormal_distribution& x); };}

[ð](#lib:lognormal_distribution,constructor)

`explicit lognormal_distribution(RealType m, RealType s = 1.0);
`

[2](#dist.norm.lognormal-2)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L5836)

*Preconditions*: 0<s[.](#dist.norm.lognormal-2.sentence-1)

[3](#dist.norm.lognormal-3)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L5840)

*Remarks*: m and s correspond to the respective parameters of the distribution[.](#dist.norm.lognormal-3.sentence-1)

[ð](#lib:m,lognormal_distribution)

`RealType m() const;
`

[4](#dist.norm.lognormal-4)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L5852)

*Returns*: The value of the m parameter
 with which the object was constructed[.](#dist.norm.lognormal-4.sentence-1)

[ð](#lib:s,lognormal_distribution)

`RealType s() const;
`

[5](#dist.norm.lognormal-5)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L5864)

*Returns*: The value of the s parameter
 with which the object was constructed[.](#dist.norm.lognormal-5.sentence-1)

#### [29.5.9.5.3](#dist.norm.chisq) Class template chi_squared_distribution [[rand.dist.norm.chisq]](rand.dist.norm.chisq)

[1](#dist.norm.chisq-1)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L5877)

A chi_squared_distribution random number distribution
produces random numbers x>0 distributed according to
the probability density function in Formula [29.15](#eq:rand.dist.norm.chisq)[.](#dist.norm.chisq-1.sentence-1)

p(x|n)=x(n/2)â1âeâx/2Î(n/2)â2n/2(29.15)

[ð](#lib:chi_squared_distribution_)

namespace std {template<class RealType = double>class chi_squared_distribution {public:// typesusing result_type = RealType; using param_type = *unspecified*; // constructor and reset functions chi_squared_distribution() : chi_squared_distribution(1.0) {}explicit chi_squared_distribution(RealType n); explicit chi_squared_distribution(const param_type& parm); void reset(); // equality operatorsfriend bool operator==(const chi_squared_distribution& x, const chi_squared_distribution& y); // generating functionstemplate<class URBG> result_type operator()(URBG& g); template<class URBG> result_type operator()(URBG& g, const param_type& parm); // property functions RealType n() const;
 param_type param() const; void param(const param_type& parm);
 result_type min() const;
 result_type max() const; // inserters and extractorstemplate<class charT, class traits>friend basic_ostream<charT, traits>&operator<<(basic_ostream<charT, traits>& os, const chi_squared_distribution& x); template<class charT, class traits>friend basic_istream<charT, traits>&operator>>(basic_istream<charT, traits>& is, chi_squared_distribution& x); };}

[ð](#lib:chi_squared_distribution,constructor)

`explicit chi_squared_distribution(RealType n);
`

[2](#dist.norm.chisq-2)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L5936)

*Preconditions*: 0<n[.](#dist.norm.chisq-2.sentence-1)

[3](#dist.norm.chisq-3)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L5940)

*Remarks*: n corresponds to the parameter of the distribution[.](#dist.norm.chisq-3.sentence-1)

[ð](#lib:n,chi_squared_distribution)

`RealType n() const;
`

[4](#dist.norm.chisq-4)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L5951)

*Returns*: The value of the n parameter
 with which the object was constructed[.](#dist.norm.chisq-4.sentence-1)

#### [29.5.9.5.4](#dist.norm.cauchy) Class template cauchy_distribution [[rand.dist.norm.cauchy]](rand.dist.norm.cauchy)

[1](#dist.norm.cauchy-1)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L5964)

A cauchy_distribution random number distribution
produces random numbers x distributed according to
the probability density function in Formula [29.16](#eq:rand.dist.norm.cauchy)[.](#dist.norm.cauchy-1.sentence-1)

p(x|a,b)=(Ïb(1+(xâab)2))â1(29.16)

[ð](#lib:cauchy_distribution_)

namespace std {template<class RealType = double>class cauchy_distribution {public:// typesusing result_type = RealType; using param_type = *unspecified*; // constructor and reset functions cauchy_distribution() : cauchy_distribution(0.0) {}explicit cauchy_distribution(RealType a, RealType b = 1.0); explicit cauchy_distribution(const param_type& parm); void reset(); // equality operatorsfriend bool operator==(const cauchy_distribution& x, const cauchy_distribution& y); // generating functionstemplate<class URBG> result_type operator()(URBG& g); template<class URBG> result_type operator()(URBG& g, const param_type& parm); // property functions RealType a() const;
 RealType b() const;
 param_type param() const; void param(const param_type& parm);
 result_type min() const;
 result_type max() const; // inserters and extractorstemplate<class charT, class traits>friend basic_ostream<charT, traits>&operator<<(basic_ostream<charT, traits>& os, const cauchy_distribution& x); template<class charT, class traits>friend basic_istream<charT, traits>&operator>>(basic_istream<charT, traits>& is, cauchy_distribution& x); };}

[ð](#lib:cauchy_distribution,constructor)

`explicit cauchy_distribution(RealType a, RealType b = 1.0);
`

[2](#dist.norm.cauchy-2)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L6025)

*Preconditions*: 0<b[.](#dist.norm.cauchy-2.sentence-1)

[3](#dist.norm.cauchy-3)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L6029)

*Remarks*: a and b correspond to the respective parameters of the distribution[.](#dist.norm.cauchy-3.sentence-1)

[ð](#lib:a,cauchy_distribution)

`RealType a() const;
`

[4](#dist.norm.cauchy-4)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L6041)

*Returns*: The value of the a parameter
 with which the object was constructed[.](#dist.norm.cauchy-4.sentence-1)

[ð](#lib:b,cauchy_distribution)

`RealType b() const;
`

[5](#dist.norm.cauchy-5)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L6053)

*Returns*: The value of the b parameter
 with which the object was constructed[.](#dist.norm.cauchy-5.sentence-1)

#### [29.5.9.5.5](#dist.norm.f) Class template fisher_f_distribution [[rand.dist.norm.f]](rand.dist.norm.f)

[1](#dist.norm.f-1)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L6066)

A fisher_f_distribution random number distribution
produces random numbers x â¥ 0 distributed according to
the probability density function in Formula [29.17](#eq:rand.dist.norm.f)[.](#dist.norm.f-1.sentence-1)

p(x|m,n)=Î((m+n)/2)Î(m/2)Î(n/2)â(mn)m/2âx(m/2)â1â(1+mxn)â(m+n)/2(29.17)

[ð](#lib:fisher_f_distribution_)

namespace std {template<class RealType = double>class fisher_f_distribution {public:// typesusing result_type = RealType; using param_type = *unspecified*; // constructor and reset functions fisher_f_distribution() : fisher_f_distribution(1.0) {}explicit fisher_f_distribution(RealType m, RealType n = 1.0); explicit fisher_f_distribution(const param_type& parm); void reset(); // equality operatorsfriend bool operator==(const fisher_f_distribution& x, const fisher_f_distribution& y); // generating functionstemplate<class URBG> result_type operator()(URBG& g); template<class URBG> result_type operator()(URBG& g, const param_type& parm); // property functions RealType m() const;
 RealType n() const;
 param_type param() const; void param(const param_type& parm);
 result_type min() const;
 result_type max() const; // inserters and extractorstemplate<class charT, class traits>friend basic_ostream<charT, traits>&operator<<(basic_ostream<charT, traits>& os, const fisher_f_distribution& x); template<class charT, class traits>friend basic_istream<charT, traits>&operator>>(basic_istream<charT, traits>& is, fisher_f_distribution& x); };}

[ð](#lib:fisher_f_distribution,constructor)

`explicit fisher_f_distribution(RealType m, RealType n = 1);
`

[2](#dist.norm.f-2)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L6129)

*Preconditions*: 0<m and 0<n[.](#dist.norm.f-2.sentence-1)

[3](#dist.norm.f-3)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L6133)

*Remarks*: m and n correspond to the respective parameters of the distribution[.](#dist.norm.f-3.sentence-1)

[ð](#lib:m,fisher_f_distribution)

`RealType m() const;
`

[4](#dist.norm.f-4)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L6145)

*Returns*: The value of the m parameter
 with which the object was constructed[.](#dist.norm.f-4.sentence-1)

[ð](#lib:n,fisher_f_distribution)

`RealType n() const;
`

[5](#dist.norm.f-5)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L6157)

*Returns*: The value of the n parameter
 with which the object was constructed[.](#dist.norm.f-5.sentence-1)

#### [29.5.9.5.6](#dist.norm.t) Class template student_t_distribution [[rand.dist.norm.t]](rand.dist.norm.t)

[1](#dist.norm.t-1)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L6170)

A student_t_distribution random number distribution
produces random numbers x distributed according to
the probability density function in Formula [29.18](#eq:rand.dist.norm.t)[.](#dist.norm.t-1.sentence-1)

p(x|n)=1ânÏâÎ((n+1)/2)Î(n/2)â(1+x2n)â(n+1)/2(29.18)

[ð](#lib:student_t_distribution_)

namespace std {template<class RealType = double>class student_t_distribution {public:// typesusing result_type = RealType; using param_type = *unspecified*; // constructor and reset functions student_t_distribution() : student_t_distribution(1.0) {}explicit student_t_distribution(RealType n); explicit student_t_distribution(const param_type& parm); void reset(); // equality operatorsfriend bool operator==(const student_t_distribution& x, const student_t_distribution& y); // generating functionstemplate<class URBG> result_type operator()(URBG& g); template<class URBG> result_type operator()(URBG& g, const param_type& parm); // property functions RealType n() const;
 param_type param() const; void param(const param_type& parm);
 result_type min() const;
 result_type max() const; // inserters and extractorstemplate<class charT, class traits>friend basic_ostream<charT, traits>&operator<<(basic_ostream<charT, traits>& os, const student_t_distribution& x); template<class charT, class traits>friend basic_istream<charT, traits>&operator>>(basic_istream<charT, traits>& is, student_t_distribution& x); };}

[ð](#lib:student_t_distribution,constructor)

`explicit student_t_distribution(RealType n);
`

[2](#dist.norm.t-2)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L6231)

*Preconditions*: 0<n[.](#dist.norm.t-2.sentence-1)

[3](#dist.norm.t-3)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L6235)

*Remarks*: n corresponds to the parameter of the distribution[.](#dist.norm.t-3.sentence-1)

[ð](#lib:mean,student_t_distribution)

`RealType n() const;
`

[4](#dist.norm.t-4)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L6246)

*Returns*: The value of the n parameter
 with which the object was constructed[.](#dist.norm.t-4.sentence-1)

#### [29.5.9.6](#dist.samp) Sampling distributions [[rand.dist.samp]](rand.dist.samp)

#### [29.5.9.6.1](#dist.samp.discrete) Class template discrete_distribution [[rand.dist.samp.discrete]](rand.dist.samp.discrete)

[1](#dist.samp.discrete-1)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L6273)

A discrete_distribution random number distribution
produces random integers i, 0â¤i<n,
distributed according to
the discrete probability function in Formula [29.19](#eq:rand.dist.samp.discrete)[.](#dist.samp.discrete-1.sentence-1)

P(i|p0,â¦,pnâ1)=pi(29.19)

[2](#dist.samp.discrete-2)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L6282)

Unless specified otherwise,
the distribution parameters are calculated as:pk=wk/S for k=0,â¦,nâ1,
in which the values wk,
commonly known as the [*weights*](#def:weights), shall be non-negative, non-NaN, and non-infinity[.](#dist.samp.discrete-2.sentence-1)

Moreover, the following relation shall hold:0<S=w0+â¯+wnâ1[.](#dist.samp.discrete-2.sentence-2)

[ð](#lib:discrete_distribution_)

namespace std {template<class IntType = int>class discrete_distribution {public:// typesusing result_type = IntType; using param_type = *unspecified*; // constructor and reset functions discrete_distribution(); template<class InputIterator> discrete_distribution(InputIterator firstW, InputIterator lastW);
 discrete_distribution(initializer_list<double> wl); template<class UnaryOperation> discrete_distribution(size_t nw, double xmin, double xmax, UnaryOperation fw); explicit discrete_distribution(const param_type& parm); void reset(); // equality operatorsfriend bool operator==(const discrete_distribution& x, const discrete_distribution& y); // generating functionstemplate<class URBG> result_type operator()(URBG& g); template<class URBG> result_type operator()(URBG& g, const param_type& parm); // property functions vector<double> probabilities() const;
 param_type param() const; void param(const param_type& parm);
 result_type min() const;
 result_type max() const; // inserters and extractorstemplate<class charT, class traits>friend basic_ostream<charT, traits>&operator<<(basic_ostream<charT, traits>& os, const discrete_distribution& x); template<class charT, class traits>friend basic_istream<charT, traits>&operator>>(basic_istream<charT, traits>& is, discrete_distribution& x); };}

[ð](#lib:discrete_distribution,constructor)

`discrete_distribution();
`

[3](#dist.samp.discrete-3)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L6346)

*Effects*: Constructs a discrete_distribution object
with n=1 and p0=1[.](#dist.samp.discrete-3.sentence-1)

[*Note [1](#dist.samp.discrete-note-1)*:

Such an object will always deliver the value 0[.](#dist.samp.discrete-3.sentence-2)

â *end note*]

[ð](#lib:discrete_distribution,constructor_)

`template<class InputIterator>
  discrete_distribution(InputIterator firstW, InputIterator lastW);
`

[4](#dist.samp.discrete-4)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L6363)

*Mandates*: is_convertible_v<iterator_traits<InputIterator>​::​value_type,double> is true[.](#dist.samp.discrete-4.sentence-1)

[5](#dist.samp.discrete-5)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L6368)

*Preconditions*: InputIterator meets the [*Cpp17InputIterator*](input.iterators#:Cpp17InputIterator "24.3.5.3 Input iterators [input.iterators]") requirements ([[input.iterators]](input.iterators "24.3.5.3 Input iterators"))[.](#dist.samp.discrete-5.sentence-1)

If firstW == lastW,
 let n=1 and w0=1[.](#dist.samp.discrete-5.sentence-2)

Otherwise, [firstW, lastW) forms a sequence w of length n>0[.](#dist.samp.discrete-5.sentence-3)

[6](#dist.samp.discrete-6)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L6378)

*Effects*: Constructs a discrete_distribution object
with probabilities given by the Formula [29.19](#eq:rand.dist.samp.discrete)[.](#dist.samp.discrete-6.sentence-1)

[ð](#lib:discrete_distribution,constructor__)

`discrete_distribution(initializer_list<double> wl);
`

[7](#dist.samp.discrete-7)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L6391)

*Effects*: Same as discrete_distribution(wl.begin(), wl.end())[.](#dist.samp.discrete-7.sentence-1)

[ð](#lib:discrete_distribution,constructor___)

`template<class UnaryOperation>
  discrete_distribution(size_t nw, double xmin, double xmax, UnaryOperation fw);
`

[8](#dist.samp.discrete-8)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L6403)

*Mandates*: is_invocable_r_v<double, UnaryOperation&, double> is true[.](#dist.samp.discrete-8.sentence-1)

[9](#dist.samp.discrete-9)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L6407)

*Preconditions*: If nw=0, let n=1, otherwise let n=nw[.](#dist.samp.discrete-9.sentence-1)

The relation 0<Î´=(xmaxâxmin)/n holds[.](#dist.samp.discrete-9.sentence-2)

[10](#dist.samp.discrete-10)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L6414)

*Effects*: Constructs a discrete_distribution object
 with probabilities given by the formula above,
 using the following values:
 If nw=0,
 let w0=1[.](#dist.samp.discrete-10.sentence-1)

Otherwise,
 let wk=fw(xmin+kâÎ´+Î´/2) for k=0,â¦,nâ1[.](#dist.samp.discrete-10.sentence-2)

[11](#dist.samp.discrete-11)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L6425)

*Complexity*: The number of invocations of fw does not exceed n[.](#dist.samp.discrete-11.sentence-1)

[ð](#lib:probabilities,discrete_distribution)

`vector<double> probabilities() const;
`

[12](#dist.samp.discrete-12)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L6436)

*Returns*: A vector<double> whose size member returns n and whose operator[] member returns pk when invoked with argument k for k=0,â¦,nâ1[.](#dist.samp.discrete-12.sentence-1)

#### [29.5.9.6.2](#dist.samp.pconst) Class template piecewise_constant_distribution [[rand.dist.samp.pconst]](rand.dist.samp.pconst)

[1](#dist.samp.pconst-1)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L6452)

A piecewise_constant_distribution random number distribution
produces random numbers x,b0â¤x<bn,
uniformly distributed over each subinterval[bi,bi+1) according to the probability density function in Formula [29.20](#eq:rand.dist.samp.pconst)[.](#dist.samp.pconst-1.sentence-1)

p(x|b0,â¦,bn,Ï0,â¦,Ïnâ1)=ÏiÂ , forÂ biâ¤x<bi+1(29.20)

[2](#dist.samp.pconst-2)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L6464)

The n+1 distribution parameters bi,
also known as this distribution's [*interval boundaries*](#def:interval_boundaries), shall satisfy the relationbi<bi+1 for i=0,â¦,nâ1[.](#dist.samp.pconst-2.sentence-1)

Unless specified otherwise,
the remaining n distribution parameters are calculated as:  
Ïk=wkSâ(bk+1âbk)Â forÂ k=0,â¦,nâ1Â , in which the values wk,
commonly known as the [*weights*](#def:weights), shall be non-negative, non-NaN, and non-infinity[.](#dist.samp.pconst-2.sentence-2)

Moreover, the following relation shall hold: 0<S=w0+â¯+wnâ1[.](#dist.samp.pconst-2.sentence-3)

[ð](#lib:piecewise_constant_distribution_)

namespace std {template<class RealType = double>class piecewise_constant_distribution {public:// typesusing result_type = RealType; using param_type = *unspecified*; // constructor and reset functions piecewise_constant_distribution(); template<class InputIteratorB, class InputIteratorW> piecewise_constant_distribution(InputIteratorB firstB, InputIteratorB lastB,
 InputIteratorW firstW); template<class UnaryOperation> piecewise_constant_distribution(initializer_list<RealType> bl, UnaryOperation fw); template<class UnaryOperation> piecewise_constant_distribution(size_t nw, RealType xmin, RealType xmax,
 UnaryOperation fw); explicit piecewise_constant_distribution(const param_type& parm); void reset(); // equality operatorsfriend bool operator==(const piecewise_constant_distribution& x, const piecewise_constant_distribution& y); // generating functionstemplate<class URBG> result_type operator()(URBG& g); template<class URBG> result_type operator()(URBG& g, const param_type& parm); // property functions vector<result_type> intervals() const;
 vector<result_type> densities() const;
 param_type param() const; void param(const param_type& parm);
 result_type min() const;
 result_type max() const; // inserters and extractorstemplate<class charT, class traits>friend basic_ostream<charT, traits>&operator<<(basic_ostream<charT, traits>& os, const piecewise_constant_distribution& x); template<class charT, class traits>friend basic_istream<charT, traits>&operator>>(basic_istream<charT, traits>& is, piecewise_constant_distribution& x); };}

[ð](#lib:piecewise_constant_distribution,constructor)

`piecewise_constant_distribution();
`

[3](#dist.samp.pconst-3)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L6538)

*Effects*: Constructs a piecewise_constant_distribution object
 with n=1, Ï0=1, b0=0,
 and b1=1[.](#dist.samp.pconst-3.sentence-1)

[ð](#lib:piecewise_constant_distribution,constructor_)

`template<class InputIteratorB, class InputIteratorW>
  piecewise_constant_distribution(InputIteratorB firstB, InputIteratorB lastB,
                                  InputIteratorW firstW);
`

[4](#dist.samp.pconst-4)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L6556)

*Mandates*: Both of

- [(4.1)](#dist.samp.pconst-4.1)

is_convertible_v<iterator_traits<InputIteratorB>​::​value_type, double>

- [(4.2)](#dist.samp.pconst-4.2)

is_convertible_v<iterator_traits<InputIteratorW>​::​value_type, double>

are true[.](#dist.samp.pconst-4.sentence-1)

[5](#dist.samp.pconst-5)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L6565)

*Preconditions*: InputIteratorB and InputIteratorW each meet the [*Cpp17InputIterator*](input.iterators#:Cpp17InputIterator "24.3.5.3 Input iterators [input.iterators]") requirements ([[input.iterators]](input.iterators "24.3.5.3 Input iterators"))[.](#dist.samp.pconst-5.sentence-1)

If firstB == lastB or ++firstB == lastB,
 let n=1, w0=1, b0=0,
 and b1=1[.](#dist.samp.pconst-5.sentence-2)

Otherwise, [firstB, lastB) forms a sequence b of length n+1,
 the length of the sequence w starting from firstW is at least n,
 and any wk for k â¥ n are ignored by the distribution[.](#dist.samp.pconst-5.sentence-3)

[6](#dist.samp.pconst-6)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L6583)

*Effects*: Constructs a piecewise_constant_distribution object
 with parameters as specified above[.](#dist.samp.pconst-6.sentence-1)

[ð](#lib:piecewise_constant_distribution,constructor__)

`template<class UnaryOperation>
  piecewise_constant_distribution(initializer_list<RealType> bl, UnaryOperation fw);
`

[7](#dist.samp.pconst-7)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L6597)

*Mandates*: is_invocable_r_v<double, UnaryOperation&, double> is true[.](#dist.samp.pconst-7.sentence-1)

[8](#dist.samp.pconst-8)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L6601)

*Effects*: Constructs a piecewise_constant_distribution object
 with parameters taken or calculated
 from the following values:
 If bl.size()<2,
 let n=1, w0=1, b0=0,
 and b1=1[.](#dist.samp.pconst-8.sentence-1)

Otherwise,
 let [bl.begin(), bl.end()) form a sequence b0,â¦,bn,
 and
 let wk=fw((bk+1+bk)/2) for k=0,â¦,nâ1[.](#dist.samp.pconst-8.sentence-2)

[9](#dist.samp.pconst-9)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L6618)

*Complexity*: The number of invocations of fw does not exceed n[.](#dist.samp.pconst-9.sentence-1)

[ð](#lib:piecewise_constant_distribution,constructor___)

`template<class UnaryOperation>
  piecewise_constant_distribution(size_t nw, RealType xmin, RealType xmax, UnaryOperation fw);
`

[10](#dist.samp.pconst-10)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L6631)

*Mandates*: is_invocable_r_v<double, UnaryOperation&, double> is true[.](#dist.samp.pconst-10.sentence-1)

[11](#dist.samp.pconst-11)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L6635)

*Preconditions*: If nw=0, let n=1, otherwise let n=nw[.](#dist.samp.pconst-11.sentence-1)

The relation 0<Î´=(xmaxâxmin)/n holds[.](#dist.samp.pconst-11.sentence-2)

[12](#dist.samp.pconst-12)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L6641)

*Effects*: Constructs a piecewise_constant_distribution object
 with parameters taken or calculated
 from the following values:
 Let bk=xmin+kâÎ´ for k=0,â¦,n,
 and wk=fw(bk+Î´/2) for k=0,â¦,nâ1[.](#dist.samp.pconst-12.sentence-1)

[13](#dist.samp.pconst-13)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L6649)

*Complexity*: The number of invocations of fw does not exceed n[.](#dist.samp.pconst-13.sentence-1)

[ð](#lib:intervals,piecewise_constant_distribution)

`vector<result_type> intervals() const;
`

[14](#dist.samp.pconst-14)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L6660)

*Returns*: A vector<result_type> whose size member returns n+1 and whose operator[] member returns bk when invoked with argument k for k=0,â¦,n[.](#dist.samp.pconst-14.sentence-1)

[ð](#lib:densities,piecewise_constant_distribution)

`vector<result_type> densities() const;
`

[15](#dist.samp.pconst-15)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L6674)

*Returns*: A vector<result_type> whose size member returns n and whose operator[] member returns Ïk when invoked with argument k for k=0,â¦,nâ1[.](#dist.samp.pconst-15.sentence-1)

#### [29.5.9.6.3](#dist.samp.plinear) Class template piecewise_linear_distribution [[rand.dist.samp.plinear]](rand.dist.samp.plinear)

[1](#dist.samp.plinear-1)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L6690)

A piecewise_linear_distribution random number distribution
produces random numbers x,b0â¤x<bn,
distributed over each subinterval[bi,bi+1) according to the probability density function in Formula [29.21](#eq:rand.dist.samp.plinear)[.](#dist.samp.plinear-1.sentence-1)

p(x|b0,â¦,bn,Ï0,â¦,Ïn)=Ïiâbi+1âxbi+1âbi+Ïi+1âxâbibi+1âbiÂ , forÂ biâ¤x<bi+1.(29.21)

[2](#dist.samp.plinear-2)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L6704)

The n+1 distribution parameters bi,
also known as this distribution's [*interval boundaries*](#def:interval_boundaries), shall satisfy the relation bi<bi+1 for i=0,â¦,nâ1[.](#dist.samp.plinear-2.sentence-1)

Unless specified otherwise,
the remaining n+1 distribution parameters are calculated asÏk=wk/S for k=0,â¦,n, in which the values wk,
commonly known as the [*weights at boundaries*](#def:weights_at_boundaries), shall be non-negative, non-NaN, and non-infinity[.](#dist.samp.plinear-2.sentence-2)

Moreover, the following relation shall hold:  
0<S=12ânâ1âk=0(wk+wk+1)â(bk+1âbk)Â [.](#dist.samp.plinear-2.sentence-3)

[ð](#lib:piecewise_linear_distribution_)

namespace std {template<class RealType = double>class piecewise_linear_distribution {public:// typesusing result_type = RealType; using param_type = *unspecified*; // constructor and reset functions piecewise_linear_distribution(); template<class InputIteratorB, class InputIteratorW> piecewise_linear_distribution(InputIteratorB firstB, InputIteratorB lastB,
 InputIteratorW firstW); template<class UnaryOperation> piecewise_linear_distribution(initializer_list<RealType> bl, UnaryOperation fw); template<class UnaryOperation> piecewise_linear_distribution(size_t nw, RealType xmin, RealType xmax, UnaryOperation fw); explicit piecewise_linear_distribution(const param_type& parm); void reset(); // equality operatorsfriend bool operator==(const piecewise_linear_distribution& x, const piecewise_linear_distribution& y); // generating functionstemplate<class URBG> result_type operator()(URBG& g); template<class URBG> result_type operator()(URBG& g, const param_type& parm); // property functions vector<result_type> intervals() const;
 vector<result_type> densities() const;
 param_type param() const; void param(const param_type& parm);
 result_type min() const;
 result_type max() const; // inserters and extractorstemplate<class charT, class traits>friend basic_ostream<charT, traits>&operator<<(basic_ostream<charT, traits>& os, const piecewise_linear_distribution& x); template<class charT, class traits>friend basic_istream<charT, traits>&operator>>(basic_istream<charT, traits>& is, piecewise_linear_distribution& x); };}

[ð](#lib:piecewise_linear_distribution,constructor)

`piecewise_linear_distribution();
`

[3](#dist.samp.plinear-3)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L6774)

*Effects*: Constructs a piecewise_linear_distribution object
 with n=1, Ï0=Ï1=1, b0=0,
 and b1=1[.](#dist.samp.plinear-3.sentence-1)

[ð](#lib:piecewise_linear_distribution,constructor_)

`template<class InputIteratorB, class InputIteratorW>
  piecewise_linear_distribution(InputIteratorB firstB, InputIteratorB lastB,
                                InputIteratorW firstW);
`

[4](#dist.samp.plinear-4)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L6791)

*Mandates*: Both of

- [(4.1)](#dist.samp.plinear-4.1)

is_convertible_v<iterator_traits<InputIteratorB>​::​value_type, double>

- [(4.2)](#dist.samp.plinear-4.2)

is_convertible_v<iterator_traits<InputIteratorW>​::​value_type, double>

are true[.](#dist.samp.plinear-4.sentence-1)

[5](#dist.samp.plinear-5)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L6800)

*Preconditions*: InputIteratorB and InputIteratorW each meet the [*Cpp17InputIterator*](input.iterators#:Cpp17InputIterator "24.3.5.3 Input iterators [input.iterators]") requirements ([[input.iterators]](input.iterators "24.3.5.3 Input iterators"))[.](#dist.samp.plinear-5.sentence-1)

If firstB == lastB or ++firstB == lastB,
 let n=1, Ï0=Ï1=1, b0=0,
 and b1=1[.](#dist.samp.plinear-5.sentence-2)

Otherwise, [firstB, lastB) forms a sequence b of length n+1,
 the length of the sequence w starting from firstW is at least n+1,
 and any wk for kâ¥n+1 are ignored by the distribution[.](#dist.samp.plinear-5.sentence-3)

[6](#dist.samp.plinear-6)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L6818)

*Effects*: Constructs a piecewise_linear_distribution object
 with parameters as specified above[.](#dist.samp.plinear-6.sentence-1)

[ð](#lib:piecewise_linear_distribution,constructor__)

`template<class UnaryOperation>
  piecewise_linear_distribution(initializer_list<RealType> bl, UnaryOperation fw);
`

[7](#dist.samp.plinear-7)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L6832)

*Mandates*: is_invocable_r_v<double, UnaryOperation&, double> is true[.](#dist.samp.plinear-7.sentence-1)

[8](#dist.samp.plinear-8)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L6836)

*Effects*: Constructs a piecewise_linear_distribution object
 with parameters taken or calculated
 from the following values:
 If bl.size()<2,
 let n=1, Ï0=Ï1=1, b0=0,
 and b1=1[.](#dist.samp.plinear-8.sentence-1)

Otherwise,
 let [bl.begin(), bl.end()) form a sequence b0,â¦,bn,
 and
 let wk=fw(bk) for k=0,â¦,n[.](#dist.samp.plinear-8.sentence-2)

[9](#dist.samp.plinear-9)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L6853)

*Complexity*: The number of invocations of fw does not exceed n+1[.](#dist.samp.plinear-9.sentence-1)

[ð](#lib:piecewise_linear_distribution,constructor___)

`template<class UnaryOperation>
  piecewise_linear_distribution(size_t nw, RealType xmin, RealType xmax, UnaryOperation fw);
`

[10](#dist.samp.plinear-10)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L6866)

*Mandates*: is_invocable_r_v<double, UnaryOperation&, double> is true[.](#dist.samp.plinear-10.sentence-1)

[11](#dist.samp.plinear-11)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L6870)

*Preconditions*: If nw=0, let n=1, otherwise let n=nw[.](#dist.samp.plinear-11.sentence-1)

The relation 0<Î´=(xmaxâxmin)/n holds[.](#dist.samp.plinear-11.sentence-2)

[12](#dist.samp.plinear-12)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L6876)

*Effects*: Constructs a piecewise_linear_distribution object
 with parameters taken or calculated
 from the following values:
 Let bk=xmin+kâÎ´ for k=0,â¦,n,
 and wk=fw(bk) for k=0,â¦,n[.](#dist.samp.plinear-12.sentence-1)

[13](#dist.samp.plinear-13)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L6884)

*Complexity*: The number of invocations of fw does not exceed n+1[.](#dist.samp.plinear-13.sentence-1)

[ð](#lib:intervals,piecewise_linear_distribution)

`vector<result_type> intervals() const;
`

[14](#dist.samp.plinear-14)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L6895)

*Returns*: A vector<result_type> whose size member returns n+1 and whose operator[] member returns bk when invoked with argument k for k=0,â¦,n[.](#dist.samp.plinear-14.sentence-1)

[ð](#lib:densities,piecewise_linear_distribution)

`vector<result_type> densities() const;
`

[15](#dist.samp.plinear-15)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L6909)

*Returns*: A vector<result_type> whose size member returns n and whose operator[] member returns Ïk when invoked with argument k for k=0,â¦,n[.](#dist.samp.plinear-15.sentence-1)

### [29.5.10](#c.math.rand) Low-quality random number generation [[c.math.rand]](c.math.rand)

[1](#c.math.rand-1)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L6923)

[*Note [1](#c.math.rand-note-1)*:

The header [<cstdlib>](cstdlib.syn#header:%3ccstdlib%3e "17.2.2 Header <cstdlib> synopsis [cstdlib.syn]") declares the functions described in this subclause[.](#c.math.rand-1.sentence-1)

â *end note*]

[ð](#lib:rand)

`int rand();
void srand(unsigned int seed);
`

[2](#c.math.rand-2)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L6937)

*Effects*: Therand and srand functions have the semantics specified in the C standard library[.](#c.math.rand-2.sentence-1)

[3](#c.math.rand-3)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L6943)

*Remarks*: The implementation
may specify that particular library functions may callrand[.](#c.math.rand-3.sentence-1)

It is implementation-defined
whether the rand function
may introduce data races ([[res.on.data.races]](res.on.data.races "16.4.6.10 Data race avoidance"))[.](#c.math.rand-3.sentence-2)

[*Note [2](#c.math.rand-note-2)*:

The other random
number generation facilities in this document ([rand]) are often preferable
to rand, because rand's underlying algorithm is unspecified[.](#c.math.rand-3.sentence-3)

Use of rand therefore continues to be non-portable, with unpredictable
and oft-questionable quality and performance[.](#c.math.rand-3.sentence-4)

â *end note*]

See also: ISO/IEC 9899:2024, 7.22.2
