RandomLib  1.10
 All Classes Namespaces Files Functions Variables Typedefs Enumerator Friends Macros Pages
Public Types | Static Public Member Functions | Static Public Attributes | List of all members
RandomLib::MT19937< RandomType > Class Template Reference

The MT19937 random number engine. More...

#include <RandomLib/RandomAlgorithm.hpp>

Public Types

enum  { N = (P + width - 1)/width }
 
typedef RandomType engine_t
 
typedef engine_t::type internal_type
 

Static Public Member Functions

static void Transition (long long count, internal_type statev[]) throw ()
 
static engine_type Generate (engine_type y) throw ()
 
static void NormalizeState (engine_type state[]) throw ()
 
static void CheckState (const engine_type state[], Random_u32::type &check)
 
static std::string Name () throw ()
 

Static Public Attributes

static const unsigned version = 0x456e4d54UL + (engine_t::width/32 - 1)
 

Detailed Description

template<class RandomType>
class RandomLib::MT19937< RandomType >

The MT19937 random number engine.

This provides an interface to Mersenne Twister random number engine, MT19937. See
Makoto Matsumoto and Takuji Nishimura,
Mersenne Twister: A 623-Dimensionally Equidistributed Uniform Pseudo-Random Number Generator,
ACM TOMACS 8, 3–30 (1998)

This is adapted from the 32-bit and 64-bit C versions available at http://www.math.sci.hiroshima-u.ac.jp/~m-mat/MT/MT2002/emt19937ar.html and http://www.math.sci.hiroshima-u.ac.jp/~m-mat/MT/emt64.html

The template argument give the type RandomType of the "natural" result. This incorporates the bit width and the C++ type of the result. Although the two versions of MT19937 produce different sequences, the implementations here are portable across 32-bit and 64-bit architectures.

The class chiefly supplies the method for advancing the state by Transition.

Template Parameters
RandomTypethe type of the results, either Random_u32 or Random_u64.

Interface routines written by Charles Karney charl.nosp@m.es@k.nosp@m.arney.nosp@m..com and licensed under the MIT/X11 License. For more information, see http://randomlib.sourceforge.net/

Definition at line 66 of file RandomAlgorithm.hpp.

Member Typedef Documentation

template<class RandomType >
typedef RandomType RandomLib::MT19937< RandomType >::engine_t

The result RandomType

Definition at line 71 of file RandomAlgorithm.hpp.

template<class RandomType >
typedef engine_t::type RandomLib::MT19937< RandomType >::internal_type

The internal numeric type for MT19337::Transition

Definition at line 75 of file RandomAlgorithm.hpp.

Member Enumeration Documentation

template<class RandomType >
anonymous enum
Enumerator
N 

The size of the state. This is the long lag for MT19937.

Definition at line 120 of file RandomAlgorithm.hpp.

Member Function Documentation

template<class RandomType >
void RandomLib::MT19937< RandomType >::Transition ( long long  count,
internal_type  statev[] 
)
throw (
)
static

Advance state by count batches. For speed all N words of state are advanced together. If count is negative, the state is stepped backwards. This is the meat of the MT19937 engine.

Parameters
[in]counthow many batches to advance.
[in,out]statevthe internal state of the random number generator.

Definition at line 687 of file Random.cpp.

References MT19937_REVSTEP, and MT19937_STEP.

template<class RandomType >
static engine_type RandomLib::MT19937< RandomType >::Generate ( engine_type  y)
throw (
)
static

Manipulate a word of the state prior to output.

Parameters
[in]ya word of the state.
Returns
the result.
template<class RandomType >
void RandomLib::MT19937< RandomType >::NormalizeState ( engine_type  state[])
throw (
)
static

Convert an arbitrary state into a legal one. This consists of (a) turning on one bit if the state is all zero and (b) making 31 bits of the state consistent with the other 19937 bits.

Parameters
[in,out]statethe state of the generator.

Definition at line 714 of file Random.cpp.

template<class RandomType >
void RandomLib::MT19937< RandomType >::CheckState ( const engine_type  state[],
Random_u32::type check 
)
static

Check that the state is legal, throwing an exception if it is not. At the same time, accumulate a checksum of the state.

Parameters
[in]statethe state of the generator.
[in,out]checkan accumulated checksum.

Definition at line 735 of file Random.cpp.

template<class RandomType >
static std::string RandomLib::MT19937< RandomType >::Name ( )
throw (
)
inlinestatic

Return the name of the engine

Returns
the name.

Definition at line 167 of file RandomAlgorithm.hpp.

Member Data Documentation

template<class RandomType >
const unsigned RandomLib::MT19937< RandomType >::version = 0x456e4d54UL + (engine_t::width/32 - 1)
static

A version number "EnMT" or "EnMU" to ensure safety of Save/Load. This needs to be unique across RandomAlgorithms.

Definition at line 119 of file RandomAlgorithm.hpp.


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