The MT19937 random number engine. More...
#include <RandomLib-2010-01/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) throw (std::out_of_range) |
static std::string | Name () throw () |
Static Public Attributes | |
static const unsigned | version = 0x456e4d54UL + (engine_t::width/32 - 1) |
Private Types | |
enum | { P = 19937, M = width == 32 ? 397 : 156, R = ((P + width - 1)/width) * width - P } |
typedef engine_t::type | engine_type |
Static Private Attributes | |
static const unsigned | width = engine_t::width |
static const engine_type | mask = engine_t::mask |
static const engine_type | magic |
static const engine_type | upper = mask << R & mask |
static const engine_type | lower = ~upper & mask |
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.
Interface routines written by Charles Karney <charles@karney.com> and licensed under the LGPL. For more information, see http://randomlib.sourceforge.net/
The result RandomType
Definition at line 58 of file RandomAlgorithm.hpp.
The internal numeric type for MT19337::Transition
Definition at line 62 of file RandomAlgorithm.hpp.
typedef engine_t::type RandomLib::MT19937::engine_type [private] |
The unsigned type of engine_t
Definition at line 67 of file RandomAlgorithm.hpp.
anonymous enum [private] |
P |
The Mersenne prime is 2P - 1 |
M |
The short lag for MT19937 |
R |
The number of ignored bits in the first word of the state |
Definition at line 72 of file RandomAlgorithm.hpp.
anonymous enum |
N |
The size of the state. This is the long lag for MT19937. |
Definition at line 107 of file RandomAlgorithm.hpp.
void RandomLib::MT19937::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.
Definition at line 689 of file Random.cpp.
References MT19937_STEP, and MT19937_REVSTEP.
static engine_type RandomLib::MT19937::Generate | ( | engine_type | y | ) | throw () [static] |
Manipulate a word of the state prior to output.
void RandomLib::MT19937::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.
Definition at line 716 of file Random.cpp.
void RandomLib::MT19937::CheckState | ( | const engine_type | state[], |
Random_u32::type & | check | ||
) | throw (std::out_of_range) [static] |
Check that the state is legal, throwing an exception if it is not. At the same time, accumulate a checksum of the state.
Definition at line 737 of file Random.cpp.
static std::string RandomLib::MT19937::Name | ( | ) | throw () [inline, static] |
const unsigned RandomLib::MT19937::width = engine_t::width [static, private] |
The width of the engine_t
Definition at line 71 of file RandomAlgorithm.hpp.
Referenced by Name(), and RandomLib::SFMT19937::Name().
const engine_type RandomLib::MT19937::mask = engine_t::mask [static, private] |
Definition at line 86 of file RandomAlgorithm.hpp.
const engine_type RandomLib::MT19937::magic [static, private] |
width == 32 ? 0x9908b0dfULL : 0xb5026f5aa96619e9ULL
Magic matrix for MT19937
Definition at line 90 of file RandomAlgorithm.hpp.
const engine_type RandomLib::MT19937::upper = mask << R & mask [static, private] |
Mask for top width - R bits of a word
Definition at line 95 of file RandomAlgorithm.hpp.
const engine_type RandomLib::MT19937::lower = ~upper & mask [static, private] |
Mask for low R bits of a width-bit word
Definition at line 99 of file RandomAlgorithm.hpp.
const unsigned RandomLib::MT19937::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 106 of file RandomAlgorithm.hpp.