dcmt-cpp  1.0.0
Public Types | Public Member Functions | Static Public Member Functions | Static Public Attributes | Friends | List of all members
dcmt::dcmt_engine< UIntType, WordSize, p > Class Template Reference

Mersenne Twister pseudo-random number generator engine. More...

#include <dcmt.h>

Public Types

using param_type = dcmt_param< UIntType, WordSize, p >
 Parameter type for the engine. More...
 
using result_type = UIntType
 Integral type generated by the engine. More...
 

Public Member Functions

 dcmt_engine (result_type seed=default_seed)
 Constructs the engine. More...
 
 dcmt_engine (const param_type &param, result_type seed=default_seed)
 Constructs the engine. More...
 
 dcmt_engine (param_type &&param, result_type seed=default_seed)
 Constructs the engine. More...
 
void seed (result_type value=default_seed)
 Reinitializes the engine by a new seed value. More...
 
result_type operator() ()
 Returns the next pseudo-random number. More...
 
void discard (unsigned long long z)
 Advances the internal state. More...
 

Static Public Member Functions

static constexpr result_type min ()
 Returns the minimum value potentially generated by the engine, which is 0. More...
 
static constexpr result_type max ()
 Returns the maximum value potentially generated by the engine. More...
 

Static Public Attributes

static constexpr std::size_t word_size = WordSize
 Word size that determines the range of numbers generated by the engine. More...
 
static constexpr std::size_t prime_exponent = p
 Mersenne prime exponent. More...
 
static constexpr result_type default_seed = 3241
 Default random seed. More...
 

Friends

bool operator== (const dcmt_engine &a, const dcmt_engine &b)
 Compares two engines. More...
 
bool operator!= (const dcmt_engine &a, const dcmt_engine &b)
 Compares two engines. More...
 
template<class CharT , class Traits >
std::basic_ostream< CharT, Traits > & operator<< (std::basic_ostream< CharT, Traits > &os, const dcmt_engine &e)
 Serializes the state of the given engine into a stream. More...
 
template<class CharT , class Traits >
std::basic_istream< CharT, Traits > & operator>> (std::basic_istream< CharT, Traits > &is, dcmt_engine &e)
 Deserializes the state of the given engine from a stream. More...
 

Detailed Description

template<class UIntType, std::size_t WordSize, std::size_t p>
class dcmt::dcmt_engine< UIntType, WordSize, p >

Mersenne Twister pseudo-random number generator engine.

Template Parameters
UIntTypeunsigned integral type for the engine
WordSizeword size for the generated numbers
pMersenne prime exponent

Member Typedef Documentation

◆ param_type

template<class UIntType , std::size_t WordSize, std::size_t p>
using dcmt::dcmt_engine< UIntType, WordSize, p >::param_type = dcmt_param<UIntType, WordSize, p>

Parameter type for the engine.

◆ result_type

template<class UIntType , std::size_t WordSize, std::size_t p>
using dcmt::dcmt_engine< UIntType, WordSize, p >::result_type = UIntType

Integral type generated by the engine.

Constructor & Destructor Documentation

◆ dcmt_engine() [1/3]

template<class UIntType , std::size_t WordSize, std::size_t p>
dcmt::dcmt_engine< UIntType, WordSize, p >::dcmt_engine ( result_type  seed = default_seed)
inlineexplicit

Constructs the engine.

Parameters
seedrandom seed

◆ dcmt_engine() [2/3]

template<class UIntType , std::size_t WordSize, std::size_t p>
dcmt::dcmt_engine< UIntType, WordSize, p >::dcmt_engine ( const param_type param,
result_type  seed = default_seed 
)
inlineexplicit

Constructs the engine.

Parameters
paramset of parameters
seedrandom seed

◆ dcmt_engine() [3/3]

template<class UIntType , std::size_t WordSize, std::size_t p>
dcmt::dcmt_engine< UIntType, WordSize, p >::dcmt_engine ( param_type &&  param,
result_type  seed = default_seed 
)
inlineexplicit

Constructs the engine.

Parameters
paramset of parameters
seedrandom seed

Member Function Documentation

◆ discard()

template<class UIntType , std::size_t WordSize, std::size_t p>
void dcmt::dcmt_engine< UIntType, WordSize, p >::discard ( unsigned long long  z)
inline

Advances the internal state.

Parameters
znumber of advances

◆ max()

template<class UIntType , std::size_t WordSize, std::size_t p>
static constexpr result_type dcmt::dcmt_engine< UIntType, WordSize, p >::max ( )
inlinestatic

Returns the maximum value potentially generated by the engine.

Returns
maximum value

◆ min()

template<class UIntType , std::size_t WordSize, std::size_t p>
static constexpr result_type dcmt::dcmt_engine< UIntType, WordSize, p >::min ( )
inlinestatic

Returns the minimum value potentially generated by the engine, which is 0.

Returns
minimum value

◆ operator()()

template<class UIntType , std::size_t WordSize, std::size_t p>
result_type dcmt::dcmt_engine< UIntType, WordSize, p >::operator() ( )
inline

Returns the next pseudo-random number.

Returns
generated value

◆ seed()

template<class UIntType , std::size_t WordSize, std::size_t p>
void dcmt::dcmt_engine< UIntType, WordSize, p >::seed ( result_type  value = default_seed)
inline

Reinitializes the engine by a new seed value.

Parameters
valuerandom seed

Friends And Related Function Documentation

◆ operator!=

template<class UIntType , std::size_t WordSize, std::size_t p>
bool operator!= ( const dcmt_engine< UIntType, WordSize, p > &  a,
const dcmt_engine< UIntType, WordSize, p > &  b 
)
friend

Compares two engines.

Parameters
afirst engine
bsecond engine
Returns
true if the engines are not equivalent including their internal states, false otherwise

◆ operator<<

template<class UIntType , std::size_t WordSize, std::size_t p>
template<class CharT , class Traits >
std::basic_ostream<CharT, Traits>& operator<< ( std::basic_ostream< CharT, Traits > &  os,
const dcmt_engine< UIntType, WordSize, p > &  e 
)
friend

Serializes the state of the given engine into a stream.

Parameters
osoutput stream
eengine to be serialized
Returns
os

◆ operator==

template<class UIntType , std::size_t WordSize, std::size_t p>
bool operator== ( const dcmt_engine< UIntType, WordSize, p > &  a,
const dcmt_engine< UIntType, WordSize, p > &  b 
)
friend

Compares two engines.

Parameters
afirst engine
bsecond engine
Returns
true if the engines are equivalent including their internal states, false otherwise

◆ operator>>

template<class UIntType , std::size_t WordSize, std::size_t p>
template<class CharT , class Traits >
std::basic_istream<CharT, Traits>& operator>> ( std::basic_istream< CharT, Traits > &  is,
dcmt_engine< UIntType, WordSize, p > &  e 
)
friend

Deserializes the state of the given engine from a stream.

Parameters
isinput stream
eengine to be deserialized
Returns
is

Member Data Documentation

◆ default_seed

template<class UIntType , std::size_t WordSize, std::size_t p>
constexpr UIntType dcmt::dcmt_engine< UIntType, WordSize, p >::default_seed = 3241
static

Default random seed.

◆ prime_exponent

template<class UIntType , std::size_t WordSize, std::size_t p>
constexpr std::size_t dcmt::dcmt_engine< UIntType, WordSize, p >::prime_exponent = p
static

Mersenne prime exponent.

◆ word_size

template<class UIntType , std::size_t WordSize, std::size_t p>
constexpr std::size_t dcmt::dcmt_engine< UIntType, WordSize, p >::word_size = WordSize
static

Word size that determines the range of numbers generated by the engine.


The documentation for this class was generated from the following file: