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 57 of file Utility.h.


Constructor & Destructor Documentation

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

Definition at line 1069 of file Utility.cpp.

References m_tmp, and TWIST_LEN.

01069                                   : m_value( 0 )
01070 {
01071         m_tmp[0] = seed & 0xffffffffUL;
01072         for (int i = 1; i < TWIST_LEN; i++)
01073         {
01074                 m_tmp[i] = (1812433253UL * (m_tmp[i - 1] ^ (m_tmp[i - 1] >> 30)) + i);
01075         }
01076 }


Member Function Documentation

unsigned long Utility::Rng::Get (  ) 

Definition at line 1079 of file Utility.cpp.

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

Referenced by Utility::Rnd().

01080 {
01081         unsigned long val = m_tmp[m_value];
01082         ++m_value;
01083         if (m_value == TWIST_LEN)
01084         {
01085                 for (int i = 0; i < TWIST_IB; ++i)
01086                 {
01087                         unsigned long s = TWIST(m_tmp, i, i + 1);
01088                         m_tmp[i] = m_tmp[i + TWIST_IA] ^ (s >> 1) ^ MAGIC_TWIST(s);
01089                 }
01090                 {
01091                         for (int i = 0; i < TWIST_LEN - 1; ++i)
01092                         {
01093                                 unsigned long s = TWIST(m_tmp, i, i + 1);
01094                                 m_tmp[i] = m_tmp[i - TWIST_IB] ^ (s >> 1) ^ MAGIC_TWIST(s);
01095                         }
01096                 }
01097                 unsigned long s = TWIST(m_tmp, TWIST_LEN - 1, 0);
01098                 m_tmp[TWIST_LEN - 1] = m_tmp[TWIST_IA - 1] ^ (s >> 1) ^ MAGIC_TWIST(s);
01099 
01100                 m_value = 0;
01101         }
01102         return val;
01103 }


Member Data Documentation

int Utility::Rng::m_value [private]

Definition at line 64 of file Utility.h.

Referenced by Get().

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

Definition at line 65 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