std::subtract_with_carry_engine
<random>
class UIntType,
std::size_t w, std::size_t s, std::size_t r
Is a random number engine that uses subtract with carry algorithm.
Contents
[edit] Template parameters
If w is not in [
1,
std::numeric_limits <UIntType>::digits]
, or s is not in [
1,
r)
, the program is ill-formed.
[edit] Generator properties
The size of the states of subtract_with_carry_engine
is \(\scriptsize O(r)\)O(r), each of them consists of two parts:
- A sequence X of r integer values, where each value is in
[
0,
2
w
)
. - An integer c (known as the carry ), whose value is either 0 or 1.
Given that \(\scriptsize X_j\)Xj stands for the \(\scriptsize j\mod r\)j mod rth value (starting from 0) of X, the transition algorithm of subtract_with_carry_engine
(\(\scriptsize TA(x_i)\)TA(xi)) is defined as follows:
- Let Y be \(\scriptsize X_{i-s}-X_{i-r}-c\)Xi-s-Xi-r-c.
- Let y be \(\scriptsize Y\mod 2^w\)Y mod 2w
, and set \(\scriptsize X_i\)Xi to y. - If Y is negative, set c to 1, otherwise set c to 0.
The generation algorithm of subtract_with_carry_engine
is \(\scriptsize GA(x_i) = y\)GA(xi) = y, where y is the value produced in step 2 of the transition algorithm.
[edit] Predefined specializations
The following specializations define the random number engine with two commonly used parameter sets:
<random>
[edit] Nested types
result_type
UIntType
[edit] Data members
[edit] Member functions
Construction and Seeding
Generation
Characteristics
(public static member function) [edit]
[edit] Non-member functions
(function) [edit]
[edit] Example
Reason: no example
[edit] Defect reports
The following behavior-changing defect reports were applied retroactively to previously published C++ standards.
DR | Applied to | Behavior as published | Correct behavior |
---|---|---|---|
LWG 3809 | C++11 | default_seed might not berepresentable with result_type
|
changed its type to std::uint_least32_t |