OpenMD  2.5
Molecular Dynamics in the Open
OpenMD::MTRand Class Reference

#include <MersenneTwister.hpp>

Public Types

enum  { N = 624 }
 
enum  { SAVE = N + 1 }
 
typedef unsigned long uint32
 

Public Member Functions

 MTRand (const uint32 &oneSeed, int nstrides, int stride)
 
 MTRand (uint32 *const bigSeed, uint32 const seedLength, int nstrides, int stride)
 
 MTRand (int nstrides, int stride)
 
RealType rand ()
 
RealType rand (const RealType &n)
 
RealType randExc ()
 
RealType randExc (const RealType &n)
 
RealType randDblExc ()
 
RealType randDblExc (const RealType &n)
 
uint32 randInt ()
 
uint32 rawRandInt ()
 
uint32 randInt (const uint32 &n)
 
RealType operator() ()
 
RealType rand53 ()
 
RealType randNorm (const RealType mean=0.0, const RealType variance=0.0)
 
void seed (const uint32 oneSeed)
 
void seed (uint32 *const bigSeed, const uint32 seedLength=N)
 
void seed ()
 
std::vector< uint32generateSeeds ()
 
void save (uint32 *saveArray) const
 
void load (uint32 *const loadArray)
 

Protected Member Functions

void initialize (const uint32 oneSeed)
 
void reload ()
 
uint32 hiBit (const uint32 &u) const
 
uint32 loBit (const uint32 &u) const
 
uint32 loBits (const uint32 &u) const
 
uint32 mixBits (const uint32 &u, const uint32 &v) const
 
uint32 twist (const uint32 &m, const uint32 &s0, const uint32 &s1) const
 

Static Protected Member Functions

static uint32 hash (time_t t, clock_t c)
 

Private Types

enum  { M = 397 }
 

Private Attributes

uint32 state [N]
 
uint32pNext
 
int left
 
int nstrides_
 
int stride_
 

Friends

std::ostream & operator<< (std::ostream &os, const MTRand &mtrand)
 
std::istream & operator>> (std::istream &is, MTRand &mtrand)
 

Detailed Description

Definition at line 72 of file MersenneTwister.hpp.

Member Typedef Documentation

◆ uint32

typedef unsigned long OpenMD::MTRand::uint32

Definition at line 75 of file MersenneTwister.hpp.

Member Enumeration Documentation

◆ anonymous enum

anonymous enum
Enumerator

Definition at line 77 of file MersenneTwister.hpp.

◆ anonymous enum

anonymous enum
Enumerator
SAVE 

Definition at line 78 of file MersenneTwister.hpp.

◆ anonymous enum

anonymous enum
private
Enumerator

Definition at line 81 of file MersenneTwister.hpp.

Constructor & Destructor Documentation

◆ MTRand() [1/3]

OpenMD::MTRand::MTRand ( const uint32 oneSeed,
int  nstrides,
int  stride 
)
inline

Definition at line 152 of file MersenneTwister.hpp.

References seed().

◆ MTRand() [2/3]

OpenMD::MTRand::MTRand ( uint32 *const  bigSeed,
uint32 const  seedLength,
int  nstrides,
int  stride 
)
inline

Definition at line 157 of file MersenneTwister.hpp.

References seed().

◆ MTRand() [3/3]

OpenMD::MTRand::MTRand ( int  nstrides,
int  stride 
)
inline

Definition at line 162 of file MersenneTwister.hpp.

References seed().

Member Function Documentation

◆ generateSeeds()

std::vector< MTRand::uint32 > OpenMD::MTRand::generateSeeds ( )
inline

Definition at line 317 of file MersenneTwister.hpp.

References hash(), and N.

Referenced by operator()(), OpenMD::ParallelRandNumGen::seed(), and seed().

◆ hash()

MTRand::uint32 OpenMD::MTRand::hash ( time_t  t,
clock_t  c 
)
inlinestaticprotected

Definition at line 378 of file MersenneTwister.hpp.

Referenced by generateSeeds(), and twist().

◆ hiBit()

uint32 OpenMD::MTRand::hiBit ( const uint32 u) const
inlineprotected

Definition at line 133 of file MersenneTwister.hpp.

Referenced by mixBits().

◆ initialize()

void OpenMD::MTRand::initialize ( const uint32  oneSeed)
inlineprotected

Definition at line 344 of file MersenneTwister.hpp.

References N, and state.

Referenced by operator()(), and seed().

◆ load()

void OpenMD::MTRand::load ( uint32 *const  loadArray)
inline

Definition at line 414 of file MersenneTwister.hpp.

References left, N, pNext, and state.

Referenced by operator()().

◆ loBit()

uint32 OpenMD::MTRand::loBit ( const uint32 u) const
inlineprotected

Definition at line 134 of file MersenneTwister.hpp.

Referenced by twist().

◆ loBits()

uint32 OpenMD::MTRand::loBits ( const uint32 u) const
inlineprotected

Definition at line 135 of file MersenneTwister.hpp.

Referenced by mixBits().

◆ mixBits()

uint32 OpenMD::MTRand::mixBits ( const uint32 u,
const uint32 v 
) const
inlineprotected

Definition at line 136 of file MersenneTwister.hpp.

References hiBit(), and loBits().

Referenced by twist().

◆ operator()()

RealType OpenMD::MTRand::operator() ( )
inline

◆ rand() [1/2]

RealType OpenMD::MTRand::rand ( )
inline

Definition at line 167 of file MersenneTwister.hpp.

References randInt().

Referenced by operator()(), OpenMD::RandNumGen::rand(), and rand().

◆ rand() [2/2]

RealType OpenMD::MTRand::rand ( const RealType &  n)
inline

Definition at line 170 of file MersenneTwister.hpp.

References rand().

◆ rand53()

RealType OpenMD::MTRand::rand53 ( )
inline

Definition at line 185 of file MersenneTwister.hpp.

References randInt().

Referenced by operator()(), and OpenMD::RandNumGen::rand53().

◆ randDblExc() [1/2]

RealType OpenMD::MTRand::randDblExc ( )
inline

Definition at line 179 of file MersenneTwister.hpp.

References randInt().

Referenced by OpenMD::RandNumGen::randDblExc(), randDblExc(), and randNorm().

◆ randDblExc() [2/2]

RealType OpenMD::MTRand::randDblExc ( const RealType &  n)
inline

Definition at line 182 of file MersenneTwister.hpp.

References randDblExc().

◆ randExc() [1/2]

RealType OpenMD::MTRand::randExc ( )
inline

Definition at line 173 of file MersenneTwister.hpp.

References randInt().

Referenced by OpenMD::RandNumGen::randExc(), randExc(), and randNorm().

◆ randExc() [2/2]

RealType OpenMD::MTRand::randExc ( const RealType &  n)
inline

Definition at line 176 of file MersenneTwister.hpp.

References randExc().

◆ randInt() [1/2]

MTRand::uint32 OpenMD::MTRand::randInt ( )
inline

This function is modified from the original to allow for random streams on parallel jobs. It now takes numbers from by striding through the random stream and picking up only one of the random numbers per nstrides_. The number it picks is the stride_'th number in the stride sequence.

Definition at line 208 of file MersenneTwister.hpp.

References nstrides_, rawRandInt(), and stride_.

Referenced by rand(), rand53(), randDblExc(), randExc(), OpenMD::RandNumGen::randInt(), and randInt().

◆ randInt() [2/2]

MTRand::uint32 OpenMD::MTRand::randInt ( const uint32 n)
inline

Definition at line 239 of file MersenneTwister.hpp.

References randInt().

◆ randNorm()

RealType OpenMD::MTRand::randNorm ( const RealType  mean = 0.0,
const RealType  variance = 0.0 
)
inline

Definition at line 191 of file MersenneTwister.hpp.

References randDblExc(), and randExc().

Referenced by operator()(), and OpenMD::RandNumGen::randNorm().

◆ rawRandInt()

MTRand::uint32 OpenMD::MTRand::rawRandInt ( )
inline

This is the original randInt function which implements the mersenne twister.

Definition at line 223 of file MersenneTwister.hpp.

References left, pNext, and reload().

Referenced by randInt().

◆ reload()

void OpenMD::MTRand::reload ( )
inlineprotected

Definition at line 362 of file MersenneTwister.hpp.

References left, M, N, pNext, state, and twist().

Referenced by operator()(), rawRandInt(), and seed().

◆ save()

void OpenMD::MTRand::save ( uint32 saveArray) const
inline

Definition at line 404 of file MersenneTwister.hpp.

References left, N, and state.

Referenced by operator()().

◆ seed() [1/3]

void OpenMD::MTRand::seed ( const uint32  oneSeed)
inline

Definition at line 259 of file MersenneTwister.hpp.

References initialize(), and reload().

Referenced by OpenMD::SeqRandNumGen::seed(), and OpenMD::ParallelRandNumGen::seed().

◆ seed() [2/3]

void OpenMD::MTRand::seed ( uint32 *const  bigSeed,
const uint32  seedLength = N 
)
inline

Definition at line 267 of file MersenneTwister.hpp.

References initialize(), N, reload(), and state.

◆ seed() [3/3]

void OpenMD::MTRand::seed ( )
inline

Definition at line 303 of file MersenneTwister.hpp.

References generateSeeds().

Referenced by MTRand(), and operator()().

◆ twist()

uint32 OpenMD::MTRand::twist ( const uint32 m,
const uint32 s0,
const uint32 s1 
) const
inlineprotected

Definition at line 142 of file MersenneTwister.hpp.

References hash(), loBit(), and mixBits().

Referenced by reload().

Friends And Related Function Documentation

◆ operator<<

std::ostream& operator<< ( std::ostream &  os,
const MTRand mtrand 
)
friend

Definition at line 425 of file MersenneTwister.hpp.

Referenced by operator()().

◆ operator>>

std::istream& operator>> ( std::istream &  is,
MTRand mtrand 
)
friend

Definition at line 434 of file MersenneTwister.hpp.

Referenced by operator()().

Member Data Documentation

◆ left

int OpenMD::MTRand::left
private

◆ nstrides_

int OpenMD::MTRand::nstrides_
private

Definition at line 86 of file MersenneTwister.hpp.

Referenced by randInt().

◆ pNext

uint32* OpenMD::MTRand::pNext
private

Definition at line 84 of file MersenneTwister.hpp.

Referenced by load(), OpenMD::operator>>(), rawRandInt(), and reload().

◆ state

uint32 OpenMD::MTRand::state[N]
private

◆ stride_

int OpenMD::MTRand::stride_
private

Definition at line 87 of file MersenneTwister.hpp.

Referenced by randInt().


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