library of assembled shared sources

http://lass.cocamware.com

lass::num::RandomMT19937 Class Reference
[Random]

implemenents a mersenne twister MT19937. More...

#include <random.h>


Public Types

typedef num::Tuint32 TValue
 type of return value.

Public Member Functions

 RandomMT19937 ()
 default constructor.
 RandomMT19937 (TValue seed)
 construct with seed.
template<typename ForwardIterator >
 RandomMT19937 (ForwardIterator first, ForwardIterator last)
 construct by a range of initializing keys Requirements:
void seed (TValue seed)
 initializes with a seed.
template<typename ForwardIterator >
void seed (ForwardIterator first, ForwardIterator last)
 initialize by a range of initializing keys Requirements:
const TValue operator() ()
 draw a random number
const TValue operator() (TValue supremum)
 draw a random number remapped to range [0, supremum)
template<typename OutputIterator >
OutputIterator getState (OutputIterator first) const
template<typename InputIterator >
void setState (InputIterator first, InputIterator last)

Static Public Attributes

static const TValue max = 0xffffffff
 maximum return value.

Private Types

enum  { stateSize_ = 624, shiftSize_ = 397 }

Private Member Functions

 LASS_META_ASSERT (sizeof(TValue)*lass::bitsPerByte==32, MersenneTwister_is_designed_to_be_a_32_bits_random_number_generator)
void reload ()
 generate N words at a time
const TValue twist (TValue a, TValue b, TValue c) const

Private Attributes

TValue state_ [stateSize_]
 the array for the state vector.
TValue index_
 index in state vector.

Static Private Attributes

static TValue wordMask_
static TValue lowerMask_
static TValue upperMask_


Detailed Description

implemenents a mersenne twister MT19937.

RandomMT19937 is the LASS implementation of the Mersenne twister. Mersenne Twister(MT) is a pseudorandom number generator developped by Makoto Matsumoto and Takuji Nishimura (alphabetical order) during 1996-1997. MT has the following merits:

M. Matsumoto and T. Nishimura, "Mersenne Twister: A 623-dimensionally equidistributed uniform pseudorandom number generator", ACM Trans. on Modeling and Computer Simulation Vol. 8, No. 1, January pp.3-30 1998, http://www.math.sci.hiroshima-u.ac.jp/~m-mat/MT/emt.html

Our version is implemented after the MT19937 standard code of 2002/1/26 (mt19937ar.c)

Definition at line 150 of file random.h.


Member Typedef Documentation

type of return value.

Definition at line 154 of file random.h.


Member Enumeration Documentation

anonymous enum [private]

Enumerator:
stateSize_  size of state vector
shiftSize_ 

Definition at line 175 of file random.h.


Constructor & Destructor Documentation

lass::num::RandomMT19937::RandomMT19937 (  ) 

default constructor.

will seed with default value on first use.

Definition at line 111 of file random.cpp.

lass::num::RandomMT19937::RandomMT19937 ( TValue  seed  )  [explicit]

construct with seed.

Definition at line 120 of file random.cpp.

References seed().

template<typename ForwardIterator >
lass::num::RandomMT19937::RandomMT19937 ( ForwardIterator  first,
ForwardIterator  last 
) [inline]

construct by a range of initializing keys Requirements:

  • ForwardIterator is a forward iterator to elements of type TValue. It must really be a forward iterator and not just an input iterator, since it must be possible to iterator over the same range more than once.

Definition at line 133 of file random.inl.

References seed().


Member Function Documentation

void lass::num::RandomMT19937::seed ( TValue  seed  ) 

initializes with a seed.

Definition at line 129 of file random.cpp.

References index_, state_, and stateSize_.

Referenced by RandomMT19937(), reload(), and seed().

template<typename ForwardIterator >
void lass::num::RandomMT19937::seed ( ForwardIterator  first,
ForwardIterator  last 
) [inline]

initialize by a range of initializing keys Requirements:

  • ForwardIterator is a forward iterator to elements of type TValue. It must really be a forward iterator and not just an input iterator, since it must be possible to iterator over the same range more than once.

Definition at line 147 of file random.inl.

References lass::bitsPerByte, lass::prim::distance(), LASS_ASSERT, LASS_META_ASSERT(), seed(), state_, and stateSize_.

const RandomMT19937::TValue lass::num::RandomMT19937::operator() (  ) 

draw a random number

Definition at line 144 of file random.cpp.

References index_, reload(), state_, and stateSize_.

const RandomMT19937::TValue lass::num::RandomMT19937::operator() ( TValue  supremum  )  [inline]

draw a random number remapped to range [0, supremum)

Deprecated:
this is A VERY BAD WAY TO DO IT!

Definition at line 200 of file random.inl.

template<typename OutputIterator >
OutputIterator lass::num::RandomMT19937::getState ( OutputIterator  first  )  const [inline]

Definition at line 208 of file random.inl.

References index_, state_, and stateSize_.

template<typename InputIterator >
void lass::num::RandomMT19937::setState ( InputIterator  first,
InputIterator  last 
) [inline]

Definition at line 217 of file random.inl.

References index_, LASS_ASSERT, state_, and stateSize_.

lass::num::RandomMT19937::LASS_META_ASSERT ( sizeof(TValue)*lass::bitsPerByte  = =32,
MersenneTwister_is_designed_to_be_a_32_bits_random_number_generator   
) [private]

Referenced by seed().

void lass::num::RandomMT19937::reload (  )  [private]

generate N words at a time

Definition at line 168 of file random.cpp.

References index_, seed(), shiftSize_, state_, stateSize_, and twist().

Referenced by operator()().

const RandomMT19937::TValue lass::num::RandomMT19937::twist ( TValue  a,
TValue  b,
TValue  c 
) const [inline, private]

Definition at line 192 of file random.cpp.

Referenced by reload().


Field Documentation

maximum return value.

Definition at line 155 of file random.h.

the array for the state vector.

Definition at line 184 of file random.h.

Referenced by getState(), operator()(), reload(), seed(), and setState().

index in state vector.

Definition at line 185 of file random.h.

Referenced by getState(), operator()(), reload(), seed(), and setState().

Definition at line 187 of file random.h.

Definition at line 188 of file random.h.

Definition at line 189 of file random.h.


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

Generated on Mon Nov 10 14:22:10 2008 for Library of Assembled Shared Sources by doxygen 1.5.7.1
SourceForge.net Logo