From cppreference.com
template<classUIntType,std::size_tw,std::size_ts,std::size_tr>classsubtract_with_carry_engine;(since C++11)Is a random number engine that uses
algorithm.
Template parameters
UIntType - The result type generated by the generator. The effect is undefined if this is not one of unsignedshort, unsignedint, unsignedlong, or unsignedlonglong. w - the word size, in bits, of the state sequence s - the short lag r - the long lag If w is not in [1, std::numeric_limits<UIntType>::digits], or s is not in [1, r), the program is ill-formed.
Generator properties
The
of the states of subtract_with_carry_engine is O(r), each of them consists of two parts:
A sequence X of r integer values, where each value is in [0, 2w
).
An integer c (known as the carry ), whose value is either 0 or 1.
Given that Xj stands for the j mod rth value (starting from 0) of X, the
of subtract_with_carry_engine (TA(xi)) is defined as follows:
Let Y be Xi-s-Xi-r-c.
Let y be Y mod 2w
, and set Xi to y.
If Y is negative, set c to 1, otherwise set c to 0.
The
of subtract_with_carry_engine is GA(xi) = y, where y is the value produced in step 2 of the transition algorithm.
Predefined specializations
The following specializations define the random number engine with two commonly used parameter sets:
Type Definition ranlux24_base(C++11)std::subtract_with_carry_engine<std::uint_fast32_t,24,10,24>
ranlux48_base(C++11)std::subtract_with_carry_engine<std::uint_fast64_t,48,5,12>
Member types
Member type Definition result_typeUIntTypeData members
[static]
w
(public static member constant)[static]
s
(public static member constant)[static]
r
(public static member constant)[static]
19780503u
(public static member constant)Member functions
Construction and Seeding
constructs the engine
(public member function)
sets the current state of the engine
(public member function)
Generation
advances the engine's state and returns the generated value
(public member function)
advances the engine's state by a specified amount
(public member function)
Characteristics
[static]
gets the smallest possible value in the output range
(public static member function)
[static]
gets the largest possible value in the output range
(public static member function)
Non-member functions
Example
Defect reports
The following behavior-changing defect reports were applied retroactively to previously published C++ standards.
DR Applied to Behavior as published Correct behavior
C++11 default_seed might not be
representable with result_typechanged its type to