C++ named requirements: RandomNumberEngine (since C++11)
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 a UniformRandomBitGenerator, and therefore may be plugged into any random number distribution in order to obtain a random number (formally, a random variate).
[edit] Requirements
A type satisfies RandomNumberEngine if it satisfies UniformRandomBitGenerator and, given the following types and values, the semantic and complexity requirements in the table below are satisfied:
E
a RandomNumberEngine type
T
E::result_type
E
E
E
T
Expression | Return type | Semantics | Complexity |
---|---|---|---|
E() | N/A | Creates an engine with the same initial state as all other default-constructed engines of type E .
|
\(\scriptsize O(n)\)O(n) |
E(x) | Creates an engine that compares equal to x. | \(\scriptsize O(n)\)O(n) | |
E(s) | Creates an engine whose initial state is determined by s. | \(\scriptsize O(n)\)O(n) | |
E(q) | Creates an engine whose initial state is determined by a single call to q.generate .
|
same as the complexity of q.generate called on a sequence whose length is n
| |
e.seed() | void | Postcondition: e == E(). | same as E() |
e.seed(s) | void | Postcondition: e == E(s). | same as E(s) |
e.seed(q) | void | Postcondition: e == E(q). | same as E(q) |
e() | T
|
Advances e’s state from ei to ei+1 (i.e. TA(ei )) and returns GA(ei ).
|
amortized constant |
e.discard(z) | void | Advances e’s state from ei to ei+z by any means equivalent to z consecutive calls of e().
|
no worse than the complexity of z consecutive calls of e() |
x == y | bool | For all positive integer i, if the ith consecutive calls of x() and y() return the same value, returns true. Otherwise returns false. | \(\scriptsize O(n)\)O(n) |
x != y | bool | !(x == y) | \(\scriptsize O(n)\)O(n) |
os << x | decltype(os)& | With fmtflags set to std::ios_base::dec | std::ios_base::left and the fill character set to the space character, writes to os the textual representation of x'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 to std::ios_base::dec , reads from is the textual representation of v's current state. If bad input is encountered, ensures that v’s state is unchanged by the operation and calls is.setstate(std::ios_base::failbit ) (which may throw std::ios_base::failure ). Precondition: is provides a textual representation that was previously written using an output stream pr satisfying all following conditions:
Postcondition: is's fmtflags are the same as before. |
\(\scriptsize O(n)\)O(n) |
[edit] Standard library
The following standard library facilities satisfy RandomNumberEngine:
(class template) [edit]
The following standard library facilities satisfy UniformRandomBitGenerator but not RandomNumberEngine: