A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://en.cppreference.com/w/cpp/language/../numeric/random/subtract_with_carry_engine.html below:

std::subtract_with_carry_engine - cppreference.com

std::subtract_with_carry_engine

Is a random number engine that uses subtract with carry algorithm.

[edit] Template parameters UIntType - The result type generated by the generator. The effect is undefined if this is not one of unsigned short, unsigned int, unsigned long, or unsigned long long. w - the word size, in bits, of the state sequence s - the short lag r - the long lag

If w is not in [1std::numeric_limits<UIntType>::digits], or s is not in [1r), 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:

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:

  1. Let Y be \(\scriptsize X_{i-s}-X_{i-r}-c\)Xi-s-Xi-r-c.
  2. Let y be \(\scriptsize Y\mod 2^w\)Y mod 2w
    , and set \(\scriptsize X_i\)Xi to y.
  3. 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:

[edit] Nested types Type Definition result_type UIntType [edit] Data members w
(public static member constant) s
(public static member constant) r
(public static member constant) 19780503u
(public static member constant) [edit] Member functions Construction and Seeding constructs the engine
(public member function) [edit] sets the current state of the engine
(public member function) [edit] Generation advances the engine's state and returns the generated value
(public member function) [edit] advances the engine's state by a specified amount
(public member function) [edit] Characteristics gets the smallest possible value in the output range
(public static member function) [edit] gets the largest possible value in the output range
(public static member function) [edit] [edit] Non-member functions [edit] 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 be
representable with result_type changed its type to
std::uint_least32_t

RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4