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 a mersenne_twister_engine random 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 sequence
  • template<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 to default_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 multiplier
  • static constexpr size_t mask_bits β€” mask bits πŸ”₯
  • static constexpr size_t shift_size β€” shift size
  • static constexpr size_t state_size β€” how big the state is
  • static constexpr result_type tempering_b β€” tempering b
  • static constexpr result_type tempering_c β€” tempering c
  • static constexpr result_type tempering_d β€” tempering d
  • static constexpr size_t tempering_l β€” tempering l
  • static constexpr size_t tempering_s β€” tempering s
  • static constexpr size_t tempering_t β€” tempering t
  • static constexpr size_t tempering_u β€” tempering u
  • static constexpr size_t word_size β€” the word size
  • static 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 a mersenne_twister_engine random number generator engine __x into the output stream __os πŸ’Œ
  • bool operator== (const mersenne_twister_engine &__lhs, const mersenne_twister_engine &__rhs) β€” compares two mersenne_twister_engine random 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 a mersenne_twister_engine random number generator engine __x from 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 πŸ’œ


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 β€” A mersenne_twister_engine random 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 β€” A mersenne_twister_engine random number generator object.
  • __rhs β€” Another mersenne_twister_engine random 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 β€” A mersenne_twister_engine random 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