HOME

TheInfoList



OR:

Subtract-with-carry is a
pseudorandom number generator A pseudorandom number generator (PRNG), also known as a deterministic random bit generator (DRBG), is an algorithm for generating a sequence of numbers whose properties approximate the properties of sequences of random numbers. The PRNG-generate ...
: one of many algorithms designed to produce a long series of random-looking numbers based on a small amount of starting data. It is of the lagged Fibonacci type introduced by
George Marsaglia George Marsaglia (March 12, 1924 – February 15, 2011) was an American mathematician and computer scientist. He is best known for creating the diehard tests, a suite of software for measuring statistical randomness. Research on random numbers ...
and Arif Zaman in 1991.A New Class of Random Number Generators
George Marsaglia and Arif Zaman, The Annals of Applied Probability, Vol. 1, No. 3, 1991
"Lagged Fibonacci" refers to the fact that each random number is a function of two of the preceding numbers at some specified, fixed offsets, or "lags".


Algorithm

Sequence generated by the subtract-with-carry engine may be described by the
recurrence relation In mathematics, a recurrence relation is an equation according to which the nth term of a sequence of numbers is equal to some combination of the previous terms. Often, only k previous terms of the sequence appear in the equation, for a parameter ...
: x(i) = (x(i-S) - x(i-R) - cy(i-1))\ \bmod\ M where cy(i) = \begin 1, & \text x(i-S) - x(i-R) - cy(i-1) < 0\\ 0, & \text \end . Constants ''S'' and ''R'' are known as the short and long lags, respectively. Therefore, expressions x(i - S) and x(i - R) correspond to the ''S''-th and ''R''-th previous terms of the sequence. ''S'' and ''R'' satisfy the condition 0 < S < R. Modulus ''M'' has the value M = 2^W, where ''W'' is the word size, in bits, of the state sequence and W > 0. The subtract-with-carry engine is one of the family of generators which includes as well add-with-carry and subtract-with-borrow engines. It is one of three random number generator engines included in the standard
C++11 C++11 is a version of the ISO/ IEC 14882 standard for the C++ programming language. C++11 replaced the prior version of the C++ standard, called C++03, and was later replaced by C++14. The name follows the tradition of naming language versions b ...
library.std::subtract_with_carry_engine
cppreference.com


References

{{Reflist Pseudorandom number generators