MTRand Class Reference

#include <MersenneTwister.h>

List of all members.

Public Member Functions

 MTRand ()
 constructors
 MTRand (unsigned int oneSeed)
 MTRand (unsigned int bigSeed[], unsigned int seedLength=N)
unsigned int randInt ()
 Access to random integers.
unsigned int randInt (unsigned int n)
 integer in [0, 2^32 - 1]
unsigned int operator() (unsigned int n)
 integer in [0, n)
float rand ()
 integer in [0, n) (for use with STL)
float randExc ()
 real number in [0,1]
float randDblExc ()
 real number in [0,1)
double rand53 ()
 real number in (0,1)
void seed ()
 real number in [0,1)
void seed (unsigned int oneSeed)
void seed (unsigned int bigSeed[], unsigned int seedLength=N)

Static Public Attributes

static const int N = 624

Protected Member Functions

void initialize (unsigned int oneSeed)
 number of values left before reload needed
void reload ()
unsigned int hiBit (unsigned int u) const
unsigned int loBit (unsigned int u) const
unsigned int loBits (unsigned int u) const
unsigned int mixBits (unsigned int u, unsigned int v) const
unsigned int twist (unsigned int m, unsigned int s0, unsigned int s1) const

Static Protected Member Functions

static unsigned int hash (time_t t, clock_t c)

Protected Attributes

unsigned int state [N]
 period parameter
unsigned int * pNext
 internal state
int left
 next value to get from state

Static Protected Attributes

static const int M = 397
 length of state vector

Detailed Description

MersenneTwister.h Mersenne Twister random number generator -- a C++ class MTRand Based on code by Makoto Matsumoto, Takuji Nishimura, and Shawn Cokus Richard J. Wagner v1.0 15 May 2003 rjwagner@writeme.com

The Mersenne Twister is an algorithm for generating random numbers. It was designed with consideration of the flaws in various other generators. The period, 2^19937-1, and the order of equidistribution, 623 dimensions, are far greater. The generator is also fast; it avoids multiplication and division, and it benefits from caches and pipelines. For more information see the inventors' web page at http:* www.math.keio.ac.jp/~matumoto/emt.html

Reference M. Matsumoto and T. Nishimura, "Mersenne Twister: A 623-Dimensionally Equidistributed Uniform Pseudo-Random Number Generator", ACM Transactions on Modeling and Computer Simulation, Vol. 8, No. 1, January 1998, pp 3-30.

Copyright (C) 1997 - 2002, Makoto Matsumoto and Takuji Nishimura, Copyright (C) 2000 - 2003, Richard J. Wagner All rights reserved.

Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:

1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.

2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.

3. The names of its contributors may not be used to endorse or promote products derived from this software without specific prior written permission.

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

The original code included the following notice:

When you use this, send an email to: matumoto@math.keio.ac.jp with an appropriate reference to your work.

It would be nice to CC: rjwagner@writeme.com and Cokus@math.washington.edu when you write. Not thread safe (unless auto-initialization is avoided and each thread has its own MTRand object)


Constructor & Destructor Documentation

MTRand::MTRand (  )  [inline]

constructors

Constructors

MTRand::MTRand ( unsigned int  oneSeed  )  [inline]
MTRand::MTRand ( unsigned int  bigSeed[],
unsigned int  seedLength = N 
) [inline]

Member Function Documentation

unsigned int MTRand::hash ( time_t  t,
clock_t  c 
) [inline, static, protected]
unsigned int MTRand::hiBit ( unsigned int  u  )  const [inline, protected]
void MTRand::initialize ( unsigned int  seed  )  [inline, protected]

number of values left before reload needed

Bookkeeping functions Initialize generator state with seed. See Knuth TAOCP Vol 2, 3rd Ed, p.106 for multiplier. In previous versions, most significant bits (MSBs) of the seed affect only MSBs of the state array. Modified 9 Jan 2002 by Makoto Matsumoto.

unsigned int MTRand::loBit ( unsigned int  u  )  const [inline, protected]
unsigned int MTRand::loBits ( unsigned int  u  )  const [inline, protected]
unsigned int MTRand::mixBits ( unsigned int  u,
unsigned int  v 
) const [inline, protected]
unsigned int MTRand::operator() ( unsigned int  n  )  [inline]

integer in [0, n)

float MTRand::rand (  )  [inline]

integer in [0, n) (for use with STL)

Access to 32-bit random numbers

Random floating-point numbers

double MTRand::rand53 (  )  [inline]

real number in (0,1)

Access to 53-bit random numbers (capacity of IEEE double precision)

By Isaku Wada.

float MTRand::randDblExc (  )  [inline]

real number in [0,1)

float MTRand::randExc (  )  [inline]

real number in [0,1]

unsigned int MTRand::randInt ( unsigned int  n  )  [inline]

integer in [0, 2^32 - 1]

Optimized by Magnus Jonsson (magnus@smartelectronix.com).

unsigned int MTRand::randInt (  )  [inline]

Access to random integers.

Random integers Pull a 32-bit integer from the generator state. Every other access function simply transforms the numbers extracted here

void MTRand::reload (  )  [inline, protected]

Generate N new values in state. Made clearer and faster by Matthew Bellew (matthew.bellew@home.com).

void MTRand::seed ( unsigned int  bigSeed[],
unsigned int  seedLength = N 
) [inline]

Seed the generator with an array of unsigned int's. There are 2^19937-1 possible initial states. This function allows all of those to be accessed by providing at least 19937 bits (with a default seed length of N = 624 unsigned int's). Any bits above the lower 32 in each element are discarded.

void MTRand::seed ( unsigned int  oneSeed  )  [inline]
void MTRand::seed (  )  [inline]

real number in [0,1)

Re-seeding functions with same behavior as initializers

Seeding functions

unsigned int MTRand::twist ( unsigned int  m,
unsigned int  s0,
unsigned int  s1 
) const [inline, protected]

Member Data Documentation

int MTRand::left [protected]

next value to get from state

const int MTRand::M = 397 [static, protected]

length of state vector

const int MTRand::N = 624 [static]
unsigned int* MTRand::pNext [protected]

internal state

unsigned int MTRand::state[N] [protected]

period parameter


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

Generated on Thu Jan 14 20:50:12 2010 for TerrainEditor by  doxygen 1.6.1