Logo
~Sockets~
~Examples~
~Contact~


Utility::Rng Class Reference

The Mersenne Twister http://www.math.keio.ac.jp/~matumoto/emt.html. More...

List of all members.


Public Member Functions

 Rng (unsigned long seed)
unsigned long Get ()

Private Attributes

int m_value
unsigned long m_tmp [TWIST_LEN]

Detailed Description

The Mersenne Twister http://www.math.keio.ac.jp/~matumoto/emt.html.

Definition at line 59 of file Utility.h.


Constructor & Destructor Documentation

Utility::Rng::Rng ( unsigned long  seed  ) 

Definition at line 1132 of file Utility.cpp.

References m_tmp, and TWIST_LEN.

01132                                   : m_value( 0 )
01133 {
01134         m_tmp[0] = seed & 0xffffffffUL;
01135         for (int i = 1; i < TWIST_LEN; ++i)
01136         {
01137                 m_tmp[i] = (1812433253UL * (m_tmp[i - 1] ^ (m_tmp[i - 1] >> 30)) + i);
01138         }
01139 }


Member Function Documentation

unsigned long Utility::Rng::Get (  ) 

Definition at line 1142 of file Utility.cpp.

References m_tmp, m_value, MAGIC_TWIST, TWIST, TWIST_IA, TWIST_IB, and TWIST_LEN.

Referenced by Utility::Rnd().

01143 {
01144         unsigned long val = m_tmp[m_value];
01145         ++m_value;
01146         if (m_value == TWIST_LEN)
01147         {
01148                 for (int i = 0; i < TWIST_IB; ++i)
01149                 {
01150                         unsigned long s = TWIST(m_tmp, i, i + 1);
01151                         m_tmp[i] = m_tmp[i + TWIST_IA] ^ (s >> 1) ^ MAGIC_TWIST(s);
01152                 }
01153                 {
01154                         for (int i = 0; i < TWIST_LEN - 1; ++i)
01155                         {
01156                                 unsigned long s = TWIST(m_tmp, i, i + 1);
01157                                 m_tmp[i] = m_tmp[i - TWIST_IB] ^ (s >> 1) ^ MAGIC_TWIST(s);
01158                         }
01159                 }
01160                 unsigned long s = TWIST(m_tmp, TWIST_LEN - 1, 0);
01161                 m_tmp[TWIST_LEN - 1] = m_tmp[TWIST_IA - 1] ^ (s >> 1) ^ MAGIC_TWIST(s);
01162 
01163                 m_value = 0;
01164         }
01165         return val;
01166 }


Member Data Documentation

int Utility::Rng::m_value [private]

Definition at line 66 of file Utility.h.

Referenced by Get().

unsigned long Utility::Rng::m_tmp[TWIST_LEN] [private]

Definition at line 67 of file Utility.h.

Referenced by Get(), and Rng().


The documentation for this class was generated from the following files:
Page, code, and content Copyright (C) 2007 by Anders Hedström
Generated for C++ Sockets by  doxygen 1.4.4