GClasses
GRandMersenneTwister Class Reference

Detailed Description

A 64-bit pseudo-random number generator based on the Mersenne Twister.

Remember: do not pass objects of this class by value as GRand objects - the resulting objects will still work, but they will not use the Mersene Twister random number generator

This class is derived from code that contained the following copyright notice:

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.

References: T. Nishimura, ``Tables of 64-bit Mersenne Twisters'' ACM Transactions on Modeling and Computer Simulation 10. (2000) 348–357. M. Matsumoto and T. Nishimura, ``Mersenne Twister: a 623-dimensionally equidistributed uniform pseudorandom number generator'' ACM Transactions on Modeling and Computer Simulation 8. (Jan. 1998) 3–30.

Any feedback is very welcome. http://www.math.hiroshima-u.ac.jp/~m-mat/MT/emt.html email: m-mat @ math.sci.hiroshima-u.ac.jp (remove spaces)

#include <GRand.h>

Inheritance diagram for GRandMersenneTwister:

Public Member Functions

 GRandMersenneTwister (uint64_t seed)
 Create a new random number generator with the given seed. More...
 
virtual ~GRandMersenneTwister ()
 Destructor. More...
 
virtual uint64_t next ()
 Returns an unsigned pseudo-random 64-bit value. More...
 
virtual void setSeed (uint64_t seed)
 Sets the seed. More...
 
virtual double uniform ()
 Returns a random number uniformly distributed on the [0,1) interval. This interval includes 0, but does not include 1. More...
 
virtual double uniform (double min, double max)
 Returns a pseudo-random double from min (inclusive) to max (exclusive). More...
 

Static Public Member Functions

static void test ()
 Performs unit tests for this class. Throws an exception if there is a failure. More...
 

Constructor & Destructor Documentation

GRandMersenneTwister::GRandMersenneTwister ( uint64_t  seed)
inline

Create a new random number generator with the given seed.

The sequence of numbers generated from the same seed is identical

Parameters
seedthe seed to use for generating numbers from the random number generator
virtual GRandMersenneTwister::~GRandMersenneTwister ( )
inlinevirtual

Destructor.

Member Function Documentation

virtual uint64_t GRandMersenneTwister::next ( )
inlinevirtual

Returns an unsigned pseudo-random 64-bit value.

Returns
an unsigned pseudo-random 64-bit value
virtual void GRandMersenneTwister::setSeed ( uint64_t  seed)
inlinevirtual

Sets the seed.

Note
If you subclass this, make sure you call GRand::setSeed (see the comment there)
Parameters
seedthe seed to use for generating numbers from the random number generator
static void GRandMersenneTwister::test ( )
static

Performs unit tests for this class. Throws an exception if there is a failure.

virtual double GRandMersenneTwister::uniform ( )
inlinevirtual

Returns a random number uniformly distributed on the [0,1) interval. This interval includes 0, but does not include 1.

This overrides the superclass treatment of the underlying integer stream to use the behavior of genrand64_real2 in the Mersenne twister code

Returns
a random number uniformly distributed on the [0,1) interval. This interval includes 0, but does not include 1.
virtual double GRandMersenneTwister::uniform ( double  min,
double  max 
)
inlinevirtual

Returns a pseudo-random double from min (inclusive) to max (exclusive).

Parameters
minthe minimum of the interval on which the samples returned are distributed
maxthe supremum of the interval on which the samples returned are distributed. max will not be generated unless max == min or unless the interval is otherwise pathological