STD::MERSENNE_TWISTER_ENGINE(3cxx)
π NAME π
okay so bestie, welcome to std::mersenne_twister_engine β the legendary Mersenne Twister random number engine from libstdc++ (that's the <pink>3cxx</pink> manual, iykyk) π
std::mersenne_twister_engine< _UIntType, __w, __n, __m, __r, __a, __u,
__d, __s, __b, __t, __c, __l, __f >
That's fourteen template parameters babe. Fourteen. She's extra and we love her for it π
β¨ SYNOPSIS β¨
First things first, the ritual:
#include <random>
π Public Types π
typedef _UIntType result_typeβ the type of the random value she's gonna hand you β¨
π Public Member Functions π
template<typename _Sseq , typename = _If_seed_seq<_Sseq>> mersenne_twister_engine (_Sseq &__q)β builds amersenne_twister_enginerandom number generator engine, seeded from the seed sequence__qπ«Άmersenne_twister_engine (result_type __sd)β the other constructor, no description given, she's mysterious like that πvoid discard (unsigned long long __z)β throws away a sequence of random numbers, extremely "not me deleting my ex's number" energy πresult_type operator() ()β the main character. generates a value πtemplate<typename _Sseq > _If_seed_seq< _Sseq > seed (_Sseq &__q)β reseeds from a seed sequencetemplate<typename _Sseq > auto seed (_Sseq &__q) -> _If_seed_seq< _Sseq >β same vibe, trailing-return-type fit βvoid seed (result_type __sd=default_seed)β reseeds from a plain value, and if you don't pass one she falls back todefault_seed(classic) πΈ
π¦ Static Public Member Functions π¦
static constexpr result_type max ()β gets the biggest possible value in the output range, no cap πstatic constexpr result_type min ()β gets the smallest possible value in the output range π§
β Static Public Attributes β
All of these are static constexpr babe, they're constants, they're not changing for anyone:
static constexpr result_type default_seedβ the default seed π«static constexpr result_type initialization_multiplierβ the init multiplierstatic constexpr size_t mask_bitsβ mask bits π₯static constexpr size_t shift_sizeβ shift sizestatic constexpr size_t state_sizeβ how big the state isstatic constexpr result_type tempering_bβ temperingbstatic constexpr result_type tempering_cβ temperingcstatic constexpr result_type tempering_dβ temperingdstatic constexpr size_t tempering_lβ temperinglstatic constexpr size_t tempering_sβ temperingsstatic constexpr size_t tempering_tβ temperingtstatic constexpr size_t tempering_uβ temperingustatic constexpr size_t word_sizeβ the word sizestatic constexpr result_type xor_maskβ the xor mask π
π«Ά Friends π«Ά
template<typename _UIntType1 , size_t __w1, size_t __n1, size_t __m1, size_t __r1, _UIntType1 __a1, size_t __u1, _UIntType1 __d1, size_t __s1, _UIntType1 __b1, size_t __t1, _UIntType1 __c1, size_t __l1, _UIntType1 __f1, typename _CharT , typename _Traits > std::basic_ostream< _CharT, _Traits > & operator<< (std::basic_ostream< _CharT, _Traits > &__os, const std::mersenne_twister_engine< _UIntType1, __w1, __n1, __m1, __r1, __a1, __u1, __d1, __s1, __b1, __t1, __c1, __l1, __f1 > &__x)β inserts the current state of amersenne_twister_enginerandom number generator engine__xinto the output stream__osπbool operator== (const mersenne_twister_engine &__lhs, const mersenne_twister_engine &__rhs)β compares twomersenne_twister_enginerandom number generator objects of the same type for equality βοΈtemplate<typename _UIntType1 , size_t __w1, size_t __n1, size_t __m1, size_t __r1, _UIntType1 __a1, size_t __u1, _UIntType1 __d1, size_t __s1, _UIntType1 __b1, size_t __t1, _UIntType1 __c1, size_t __l1, _UIntType1 __f1, typename _CharT , typename _Traits > std::basic_istream< _CharT, _Traits > & operator>> (std::basic_istream< _CharT, _Traits > &__is, std::mersenne_twister_engine< _UIntType1, __w1, __n1, __m1, __r1, __a1, __u1, __d1, __s1, __b1, __t1, __c1, __l1, __f1 > &__x)β extracts the current state of amersenne_twister_enginerandom number generator engine__xfrom the input stream__isπ
π₯ DETAILED DESCRIPTION π₯
template<typename _UIntType, size_t __w, size_t __n, size_t __m, size_t __r,
_UIntType __a, size_t __u, _UIntType __d, size_t __s, _UIntType __b,
size_t __t, _UIntType __c, size_t __l, _UIntType __f>
class std::mersenne_twister_engine< _UIntType, __w, __n, __m, __r, __a,
__u, __d, __s, __b, __t, __c, __l, __f >
So what is she? She's a "A generalized feedback shift register discrete random number generator." β¨
This algorithm avoids multiplication and division and is designed to be friendly to a pipelined architecture. If the parameters are chosen correctly, this generator will produce numbers with a very long period and fairly good apparent entropy β although still not cryptographically strong. So like, do not use her for your passwords bestie, she said so herself π
The best way to use this generator is with the predefined mt19937 class. That's the whole tip, take it or leave it π
This algorithm was originally invented by Makoto Matsumoto and Takuji Nishimura. kings ππ
πΈ Template Parameters πΈ
Every single one, annotated, because she deserves it:
__wβ Word size, the number of bits in each element of the state vector.__nβ The degree of recursion.__mβ The period parameter.__rβ The separation point bit index.__aβ The last row of the twist matrix.__uβ The first right-shift tempering matrix parameter.__dβ The first right-shift tempering matrix mask.__sβ The first left-shift tempering matrix parameter.__bβ The first left-shift tempering matrix mask.__tβ The second left-shift tempering matrix parameter.__cβ The second left-shift tempering matrix mask.__lβ The second right-shift tempering matrix parameter.__fβ Initialization multiplier.
π¦ Since π¦
C++11 β vintage but make it iconic π
π MEMBER TYPEDEF DOCUMENTATION π
template<typename _UIntType , size_t __w , size_t __n , size_t __m , size_t
__r , _UIntType __a , size_t __u , _UIntType __d , size_t __s , _UIntType
__b , size_t __t , _UIntType __c , size_t __l , _UIntType __f > typedef
_UIntType std::mersenne_twister_engine< _UIntType, __w, __n, __m, __r,
__a, __u, __d, __s, __b, __t, __c, __l, __f >::result_type
The type of the generated random value. that's it, that's the whole typedef, and honestly she ate β¨
π CONSTRUCTOR & DESTRUCTOR DOCUMENTATION π
template<typename _UIntType , size_t __w , size_t __n , size_t __m , size_t
__r , _UIntType __a , size_t __u , _UIntType __d , size_t __s , _UIntType
__b , size_t __t , _UIntType __c , size_t __l , _UIntType __f >
template<typename _Sseq , typename = _If_seed_seq<_Sseq>>
std::mersenne_twister_engine< _UIntType, __w, __n, __m, __r, __a, __u,
__d, __s, __b, __t, __c, __l, __f >::mersenne_twister_engine (_Sseq &
__q) [inline], [explicit]
Constructs a mersenne_twister_engine random number generator engine seeded from the seed sequence __q π±
Parameters
__qβ the seed sequence.
heads up: she's [explicit] so no accidental implicit conversions sneaking in, we love a boundary-setting queen π«Ά
π MEMBER FUNCTION DOCUMENTATION π
discard
template<typename _UIntType , size_t __w , size_t __n , size_t __m , size_t
__r , _UIntType __a , size_t __u , _UIntType __d , size_t __s , _UIntType
__b , size_t __t , _UIntType __c , size_t __l , _UIntType __f > void
std::mersenne_twister_engine< _UIntType, __w, __n, __m, __r, __a, __u,
__d, __s, __b, __t, __c, __l, __f >::discard (unsigned long long __z)
Discard a sequence of random numbers. bye bye numbers, don't let the door hit you π
max
template<typename _UIntType , size_t __w , size_t __n , size_t __m , size_t
__r , _UIntType __a , size_t __u , _UIntType __d , size_t __s , _UIntType
__b , size_t __t , _UIntType __c , size_t __l , _UIntType __f > static
constexpr result_type std::mersenne_twister_engine< _UIntType, __w, __n,
__m, __r, __a, __u, __d, __s, __b, __t, __c, __l, __f >::max ()
[inline], [static], [constexpr]
Gets the largest possible value in the output range. the ceiling, the limit, the "you can't sit with us" π«Ά
min
template<typename _UIntType , size_t __w , size_t __n , size_t __m , size_t
__r , _UIntType __a , size_t __u , _UIntType __d , size_t __s , _UIntType
__b , size_t __t , _UIntType __c , size_t __l , _UIntType __f > static
constexpr result_type std::mersenne_twister_engine< _UIntType, __w, __n,
__m, __r, __a, __u, __d, __s, __b, __t, __c, __l, __f >::min ()
[inline], [static], [constexpr]
Gets the smallest possible value in the output range. the floor, she's humble π
β FRIENDS AND RELATED SYMBOL DOCUMENTATION β
operator<<
template<typename _UIntType , size_t __w , size_t __n , size_t __m , size_t
__r , _UIntType __a , size_t __u , _UIntType __d , size_t __s , _UIntType
__b , size_t __t , _UIntType __c , size_t __l , _UIntType __f >
template<typename _UIntType1 , size_t __w1 , size_t __n1 , size_t __m1,
size_t __r1 , _UIntType1 __a1 , size_t __u1 , _UIntType1 __d1 , size_t __s1 ,
_UIntType1 __b1 , size_t __t1 , _UIntType1 __c1 , size_t __l1 , _UIntType1
__f1 , typename _CharT , typename _Traits > std::basic_ostream< _CharT,
_Traits > & operator<< (std::basic_ostream< _CharT, _Traits > & __os,
const std::mersenne_twister_engine< _UIntType1, __w1, __n1, __m1, __r1,
__a1, __u1, __d1, __s1, __b1, __t1, __c1, __l1, __f1 > & __x) [friend]
Inserts the current state of a mersenne_twister_engine random number generator engine __x into the output stream __os. state dump but make it cute π€
Parameters
__osβ An output stream.__xβ Amersenne_twister_enginerandom number generator engine.
Returns
The output stream with the state of __x inserted or in an error state.
operator==
template<typename _UIntType , size_t __w , size_t __n , size_t __m , size_t
__r , _UIntType __a , size_t __u , _UIntType __d , size_t __s , _UIntType
__b , size_t __t , _UIntType __c , size_t __l , _UIntType __f > bool
operator== (const mersenne_twister_engine< _UIntType, __w, __n, __m,
__r, __a, __u, __d, __s, __b, __t, __c, __l, __f > & __lhs, const
mersenne_twister_engine< _UIntType, __w, __n, __m, __r, __a, __u, __d,
__s, __b, __t, __c, __l, __f > & __rhs) [friend]
Compares two mersenne_twister_engine random number generator objects of the same type for equality. are they the same girl? let's find out βοΈ
Parameters
__lhsβ Amersenne_twister_enginerandom number generator object.__rhsβ Anothermersenne_twister_enginerandom number generator object.
Returns
true if the infinite sequences of generated values would be equal, false otherwise. (infinite. sequences. no biggie π)
operator>>
template<typename _UIntType , size_t __w , size_t __n , size_t __m , size_t
__r , _UIntType __a , size_t __u , _UIntType __d , size_t __s , _UIntType
__b , size_t __t , _UIntType __c , size_t __l , _UIntType __f >
template<typename _UIntType1 , size_t __w1 , size_t __n1 , size_t __m1,
size_t __r1 , _UIntType1 __a1 , size_t __u1 , _UIntType1 __d1 , size_t __s1 ,
_UIntType1 __b1 , size_t __t1 , _UIntType1 __c1 , size_t __l1 , _UIntType1
__f1 , typename _CharT , typename _Traits > std::basic_istream< _CharT,
_Traits > & operator>> (std::basic_istream< _CharT, _Traits > & __is,
std::mersenne_twister_engine< _UIntType1, __w1, __n1, __m1, __r1, __a1,
__u1, __d1, __s1, __b1, __t1, __c1, __l1, __f1 > & __x) [friend]
Extracts the current state of a mersenne_twister_engine random number generator engine __x from the input stream __is. reading her state back in, consent era π₯
Parameters
__isβ An input stream.__xβ Amersenne_twister_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. yes she was auto-generated and she's still serving looks, the algorithm ate π₯
okay that's the whole page bestie, mwah π this was page <pink>libststd::mersenne_t...__c, __l, __f >(3cxx)</pink> from the libstdc++ manual, the <pink>3cxx</pink> collection β go seed something iconic and remember: she's got a long period but she is not cryptographically strong πβ¨ππ«Ά
π¦ where this page comes from
- ubuntu noble: libstdc++-14-doc 14-20240412-0ubuntu1
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms