STD::SUBTRACT_WITH_CARRY_ENGINE(3)
π std::subtract_with_carry_engine< _UIntType, __w, __s, __r > π
okay bestie, welcome to the Library Functions Manual section of the libstdc++ docs β¨ this one lives in <random> and it is literally the Marsaglia-Zaman generator. yes, those Marsaglia-Zaman. iconic behavior fr fr π
πΈ NAME πΈ
std::subtract_with_carry_engine< _UIntType, __w, __s, __r > β The Marsaglia-Zaman generator. periodt π
β¨ SYNOPSIS β¨
#include <random>
π¦ Public Types π¦
typedef _UIntType result_typeβ the type of the generated random value. that's it, that's the type π«Ά
π Public Member Functions π
template<typename _Sseq, typename = _If_seed_seq<_Sseq>> subtract_with_carry_engine (_Sseq &__q)β Constructs asubtract_with_carry_enginerandom number engine seeded from the seed sequence__q.subtract_with_carry_engine (result_type __sd)β Constructs an explicitly seededsubtract_with_carry_enginerandom number generator. you're picking the seed yourself, main character energy πvoid discard (unsigned long long __z)β Discard a sequence of random numbers.result_type operator() ()β Gets the next random number in the sequence.template<typename _Sseq> _If_seed_seq< _Sseq > seed (_Sseq &__q)β Seeds the initial state $x_0$ of the %subtract_with_carry_enginerandom number generator.void seed (result_type __sd=0u)β Seeds the initial state $x_0$ of the random number generator.
π Static Public Member Functions π
static constexpr result_type max ()β Gets the inclusive maximum value of the range of random integers returned by this generator.static constexpr result_type min ()β Gets the inclusive minimum value of the range of random integers returned by this generator.
β Static Public Attributes β
static constexpr uint_least32_t default_seedstatic constexpr size_t long_lagstatic constexpr size_t short_lagstatic constexpr size_t word_size
π Friends π
template<typename _UIntType1, size_t __w1, size_t __s1, size_t __r1, typename _CharT, typename _Traits> std::basic_ostream< _CharT, _Traits > & operator<< (std::basic_ostream< _CharT, _Traits > &__os, const std::subtract_with_carry_engine< _UIntType1, __w1, __s1, __r1 > &__x)β Inserts the current state of a %subtract_with_carry_enginerandom number generator engine__xinto the output stream__os.bool operator== (const subtract_with_carry_engine &__lhs, const subtract_with_carry_engine &__rhs)β Compares two %subtract_with_carry_enginerandom number generator objects of the same type for equality.template<typename _UIntType1, size_t __w1, size_t __s1, size_t __r1, typename _CharT, typename _Traits> std::basic_istream< _CharT, _Traits > & operator>> (std::basic_istream< _CharT, _Traits > &__is, std::subtract_with_carry_engine< _UIntType1, __w1, __s1, __r1 > &__x)β Extracts the current state of a %subtract_with_carry_enginerandom number generator engine__xfrom the input stream__is.
π§ Detailed Description π§
template<typename _UIntType, size_t __w, size_t __s, size_t __r>
class std::subtract_with_carry_engine< _UIntType, __w, __s, __r >
"The Marsaglia-Zaman generator.
This is a model of a Generalized Fibonacci discrete random number generator, sometimes referred to as the SWC generator.
A discrete random number generator that produces pseudorandomonumbers using:
x_{i}tarrow(x_{i - s} - x_{i - r} - carry_{i-1}) d ]
The size of the state is $r$ and the maximum period of the generator is $(m^r - m^s - 1)$.
Since C++11
π Member Typedef Documentation π
template<typename _UIntType, size_t __w, size_t __s, size_t __r> typedef _UIntType std::subtract_with_carry_engine< _UIntType, __w, __s, __r >::result_type
The type of the generated random value.
π Constructor & Destructor Documentation π
template<typename _UIntType, size_t __w, size_t __s, size_t __r>
std::subtract_with_carry_engine< _UIntType, __w, __s, __r >::subtract_with_carry_engine (result_type __sd) [inline], [explicit]
Constructs an explicitly seeded subtract_with_carry_engine random number generator.
template<typename _UIntType, size_t __w, size_t __s, size_t __r>
template<typename _Sseq, typename = _If_seed_seq<_Sseq>>
std::subtract_with_carry_engine< _UIntType, __w, __s, __r >::subtract_with_carry_engine (_Sseq & __q) [inline], [explicit]
Constructs a subtract_with_carry_engine random number engine seeded from the seed sequence __q.
Parameters
__qβ the seed sequence.
π₯ Member Function Documentation π₯
template<typename _UIntType, size_t __w, size_t __s, size_t __r> void
std::subtract_with_carry_engine< _UIntType, __w, __s, __r >::discard
(unsigned long long __z) [inline]
Discard a sequence of random numbers.
template<typename _UIntType, size_t __w, size_t __s, size_t __r> constexpr
result_type std::subtract_with_carry_engine< _UIntType, __w, __s, __r
>::max () [inline], [static], [constexpr]
Gets the inclusive maximum value of the range of random integers returned by this generator.
template<typename _UIntType, size_t __w, size_t __s, size_t __r> constexpr
result_type std::subtract_with_carry_engine< _UIntType, __w, __s, __r
>::min () [inline], [static], [constexpr]
Gets the inclusive minimum value of the range of random integers returned by this generator.
template<typename _UIntType, size_t __w, size_t __s, size_t __r>
subtract_with_carry_engine< _UIntType, __w, __s, __r >::result_type
std::subtract_with_carry_engine< _UIntType, __w, __s, __r >::operator()
()
Gets the next random number in the sequence.
template<typename _UIntType, size_t __w, size_t __s, size_t __r>
template<typename _Sseq> auto std::subtract_with_carry_engine<
_UIntType, __w, __s, __r >::seed (_Sseq & __q) -> _If_seed_seq< _Sseq >
Seeds the initial state $x_0$ of the % subtract_with_carry_engine random number generator.
template<typename _UIntType, size_t __w, size_t __s, size_t __r> void
std::subtract_with_carry_engine< _UIntType, __w, __s, __r >::seed
(result_type __sd = 0u)
Seeds the initial state $x_0$ of the random number generator. N1688[4.19] modifies this as follows. If __value == 0, sets value to 19780503. In any case, with a linear congruential generator lcg(i) having parameters
$ m_{lcg} = 2147483563, a_{lcg} = 40014, c_{log} = 0, and ocg(0) = value $
sets
$ x_{-r} ots x_{-1} $
to
$ lcg(1) d ots lcg(r) d $
respectively. If
$ x_{-1} = 0 $
set carry to 1, otherwise sets carry to 0.
Referenced by std::subtract_with_carry_engine< uint_fast32_t, 24, 10, 24 >::subtract_with_carry_engine(), and std::subtract_with_carry_engine< uint_fast32_t, 24, 10, 24 >::subtract_with_carry_engine().
π«Ά Friends And Related Symbol Documentation π«Ά
template<typename _UIntType, size_t __w, size_t __s, size_t __r>
template<typename _UIntType1, size_t __w1, size_t __s1, size_t __r1,
typename _CharT, typename _Traits> std::basic_ostream< _CharT, _Traits >
& operator<< (std::basic_ostream< _CharT, _Traits > & __os, const
std::subtract_with_carry_engine< _UIntType1, __w1, __s1, __r1 > & __x)
[friend]
Inserts the current state of a % subtract_with_carry_engine random number generator engine __x into the output stream __os.
Parameters
__osβ An output stream.__xβ A %subtract_with_carry_enginerandom number generator engine.
Returns
The output stream with the state of __x inserted or in an error state.
template<typename _UIntType, size_t __w, size_t __s, size_t __r> bool
operator== (const subtract_with_carry_engine< _UIntType, __w, __s, __r >
& __lhs, const subtract_with_carry_engine< _UIntType, __w, __s, __r > &
__rhs) [friend]
Compares two % subtract_with_carry_engine random number generator objects of the same type for equality.
Parameters
__lhsβ A %subtract_with_carry_enginerandom number generator object.__rhsβ Another %subtract_with_carry_enginerandom number generator object.
Returns
true if the infinite sequences of generated values would be equal, false otherwise.
template<typename _UIntType, size_t __w, size_t __s, size_t __r>
template<typename _UIntType1, size_t __w1, size_t __s1, size_t __r1,
typename _CharT, typename _Traits> std::basic_istream< _CharT, _Traits >
& operator>> (std::basic_istream< _CharT, _Traits > & __is,
std::subtract_with_carry_engine< _UIntType1, __w1, __s1, __r1 > & __x)
[friend]
Extracts the current state of a % subtract_with_carry_engine random number generator engine __x from the input stream __is.
Parameters
__isβ An input stream.__xβ A %subtract_with_carry_enginerandom number generator engine.
Returns
The input stream with the state of __x extracted or in an error state.
π Author π
Generated automatically by Doxygen for libstdc++ from the source code.
and that's the whole page bestie, no cap πβ¨ it came straight from the libstdc++ source, auto-generated by Doxygen, and it's giving peak documentation vibes. go forth and generate pseudorandom numbers responsibly, ily ππ¦π
π¦ where this page comes from
- arch rolling: gcc 16.2.1+r23+gd564253eb6c8-1 Β· GPL-3.0-or-later WITH GCC-exception-3.1 AND GFDL-1.3-or-later
- fedora 44: libstdc++-docs 16.0.1-0.10.fc44 Β· GPL-3.0-or-later AND LGPL-3.0-or-later AND (GPL-3.0-or-later WITH GCC-exception-3.1) AND (GPL-3.0-or-later WITH Texinfo-exception) AND (LGPL-2.1-or-later WITH GCC-exception-2.0) AND (GPL-2.0-or-later WITH GCC-exception-2.0) AND (GPL-2.0-or-later WITH GNU-compiler-exception) AND BSL-1.0 AND GFDL-1.3-or-later AND Linux-man-pages-copyleft-2-para AND SunPro AND BSD-1-Clause AND BSD-2-Clause AND BSD-2-Clause-Views AND BSD-3-Clause AND BSD-4-Clause AND BSD-Source-Code AND Zlib AND MIT AND Apache-2.0 AND (Apache-2.0 WITH LLVM-Exception) AND ZPL-2.1 AND ISC AND LicenseRef-Fedora-Public-Domain AND HP-1986 AND curl AND Martin-Birgmeier AND HPND-Markus-Kuhn AND dtoa AND SMLNJ AND AMD-newlib AND OAR AND HPND-merchantability-variant AND HPND-Intel
- fedora 44: libstdc++-docs 16.2.1-2.fc44
- fedora 44: libstdc++-docs 16.2.1-3.fc44 Β· GPL-3.0-or-later AND LGPL-3.0-or-later AND (GPL-3.0-or-later WITH GCC-exception-3.1) AND (GPL-3.0-or-later WITH Texinfo-exception) AND (LGPL-2.1-or-later WITH GCC-exception-2.0) AND (GPL-2.0-or-later WITH GCC-exception-2.0) AND (GPL-2.0-or-later WITH GNU-compiler-exception) AND BSL-1.0 AND GFDL-1.3-or-later AND Linux-man-pages-copyleft-2-para AND SunPro AND BSD-1-Clause AND BSD-2-Clause AND BSD-2-Clause-Views AND BSD-3-Clause AND BSD-4-Clause AND BSD-Source-Code AND Zlib AND MIT AND Apache-2.0 AND (Apache-2.0 WITH LLVM-Exception) AND ZPL-2.1 AND ISC AND LicenseRef-Fedora-Public-Domain AND HP-1986 AND curl AND Martin-Birgmeier AND HPND-Markus-Kuhn AND dtoa AND SMLNJ AND AMD-newlib AND OAR AND HPND-merchantability-variant AND HPND-Intel
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms