|
|
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
A random number engine is a function object returning unsigned integer values such that each value in the range of possible results has (ideally) equal probability.
Any random number engine is also aUniformRandomBitGenerator, and therefore may be plugged into anyrandom number distribution in order to obtain a random number (formally, a random variate).
A type satisfiesRandomNumberEngine if it satisfiesUniformRandomBitGenerator and, given the following types and values, the semantic and complexity requirements in the table below are satisfied:
| Type | Definition |
E | aRandomNumberEngine type |
T | E::result_type |
| Value | Definition |
| e | a value of typeE |
| v | an lvalue of typeE |
| x,y | values of type (possibly const-qualified)E |
| s | a value of typeT |
| q | aSeedSequence lvalue |
| z | a value of typeunsignedlonglong |
| os | an lvalue whose type is a specialization ofstd::basic_ostream |
| is | an lvalue whose type is a specialization ofstd::basic_istream |
| n | thesize ofE's state |
| TA | thetransition algorithm ofE |
| GA | thegeneration algorithm ofE |
| Expression | Return type | Semantics | Complexity |
|---|---|---|---|
| E() | N/A | Creates an engine with the same initial state as all other default-constructed engines of typeE. | \(\scriptsize O(n)\)O(n) |
| E(x) | Creates an engine that compares equal tox. | \(\scriptsize O(n)\)O(n) | |
| E(s) | Creates an engine whose initial state is determined bys. | \(\scriptsize O(n)\)O(n) | |
| E(q) | Creates an engine whose initial state is determined by a single call toq.generate. | same as the complexity ofq.generate called on a sequence whose length isn | |
| e.seed() | void | Postcondition:e== E(). | same asE() |
| e.seed(s) | void | Postcondition:e== E(s). | same asE(s) |
| e.seed(q) | void | Postcondition:e== E(q). | same asE(q) |
| e() | T | Advancese’s state fromei toei+1 (i.e.TA(ei)) and returnsGA(ei). | amortized constant |
| e.discard(z) | void | Advancese’s state fromei toei+z by any means equivalent toz consecutive calls ofe(). | no worse than the complexity ofz consecutive calls ofe() |
| x== y | bool | For all positive integeri, if theith consecutive calls ofx() andy() return the same value, returnstrue. Otherwise returnsfalse. | \(\scriptsize O(n)\)O(n) |
| x!= y | bool | !(x== y) | \(\scriptsize O(n)\)O(n) |
| os<< x | decltype(os)& | With fmtflags set tostd::ios_base::dec|std::ios_base::left and the fill character set to the space character, writes toos the textual representation ofx's current state. Postcondition:os's fmtflags and the fill character are the same as before. | \(\scriptsize O(n)\)O(n) |
| is>> v | decltype(is)& | With fmtflags set tostd::ios_base::dec, reads fromis the textual representation ofv's current state. If bad input is encountered, ensures thatv’s state is unchanged by the operation and callsis.setstate(std::ios_base::failbit) (which may throwstd::ios_base::failure). Precondition:is provides a textual representation that was previously written using an output streampr satisfying all following conditions:
Postcondition:is's fmtflags are the same as before. | \(\scriptsize O(n)\)O(n) |
The following standard library facilities satisfyRandomNumberEngine:
(C++11) | implementslinear congruential algorithm (class template)[edit] |
(C++11) | implementsMersenne twister algorithm (class template)[edit] |
(C++11) | implements a subtract-with-carry (lagged Fibonacci) algorithm (class template)[edit] |
(C++26) | a counter-based parallelizable generator (class template)[edit] |
(C++11) | discards some output of a random number engine (class template)[edit] |
(C++11) | packs the output of a random number engine into blocks of a specified number of bits (class template)[edit] |
(C++11) | delivers the output of a random number engine in a different order (class template)[edit] |
The following standard library facilities satisfyUniformRandomBitGenerator but notRandomNumberEngine:
(C++11) | non-deterministic random number generator using hardware entropy source (class)[edit] |