SourcePro® API Reference Guide

 
Loading...
Searching...
No Matches
RWRandGenMTwist Class Reference

Generates random numbers uniformly distributed over the interval [0, 1]. More...

#include <rw/randmtwist.h>

Public Member Functions

 RWRandGenMTwist ()
 
 RWRandGenMTwist (const RWRandGenMTwist &u)
 
 RWRandGenMTwist (unsigned long seed)
 
double operator() ()
 
RWRandGenMTwistoperator= (const RWRandGenMTwist &u)
 
void printOn (std::ostream &s) const
 
void restart ()
 
void restart (unsigned long seed)
 
void restoreFrom (RWFile &)
 
void restoreFrom (RWvistream &)
 
void saveOn (RWFile &) const
 
void saveOn (RWvostream &) const
 
void scanFrom (std::istream &s)
 
unsigned long seed () const
 

Friends

bool operator== (const RWRandGenMTwist &lhs, const RWRandGenMTwist &rhs)
 

Related Symbols

(Note that these are not member symbols.)

bool operator!= (const RWRandGenMTwist &lhs, const RWRandGenMTwist &rhs)
 
std::ostream & operator<< (std::ostream &s, const RWRandGenMTwist &gen)
 
std::istream & operator>> (std::istream &s, RWRandGenMTwist &gen)
 

Detailed Description

Class RWRandGenMTwist generates random numbers uniformly distributed over the interval [0, 1], and may be used instead of class RWRandGenerator as a template parameter to any of the distribution generators derived from abstract base class RWTRand. RWRandGenMTwist uses Takuji Nishimura and Makoto Matsumoto's Mersenne Twister algorithm. It is relatively fast, and has a large period (2^19937-1).

Unlike class RWRandGenerator, each instance of RWRandGenMTwist contains and maintains its own, independent state. This can make it easier to use in some situations. The "internal state" of an instance of RWRandGenMTwist consists of a table of an unsigned long seed, an array of unsigned longs known as the "state vector" and an integer index into that state vector.

Additional information about the Mersenne Twister algorithm is available in the original article: M. Matsumoto and T. Nishimura,"Mersenne Twister: A 623-dimensionally equidistributed uniform pseudorandom number generator", ACM Trans. on Modeling and Computer Simulation Vol. 8, No. 1, January pp.3-30 1998. There are also numerous resources on the internet, including a website dedicated to the Mersenne Twister.

Synopsis
#include <rw/randmtwist.h>
Generates random numbers uniformly distributed over the interval [0, 1].
Definition randmtwist.h:136

Constructor & Destructor Documentation

◆ RWRandGenMTwist() [1/3]

RWRandGenMTwist::RWRandGenMTwist ( )

Constructs a generator, arbitrarily seeded by a call to the time() function.

◆ RWRandGenMTwist() [2/3]

RWRandGenMTwist::RWRandGenMTwist ( unsigned long seed)
explicit

Constructs a generator with a specified seed.

◆ RWRandGenMTwist() [3/3]

RWRandGenMTwist::RWRandGenMTwist ( const RWRandGenMTwist & u)

Constructs a copy of u. The copy's state will equal the state of u at the time the copy is created, but will not share the state of u.

Member Function Documentation

◆ operator()()

double RWRandGenMTwist::operator() ( )

Returns a random double in [0,1].

◆ operator=()

RWRandGenMTwist & RWRandGenMTwist::operator= ( const RWRandGenMTwist & u)

Sets an instance of RWRandGenMTwist equal to the state of instance u.

◆ printOn()

void RWRandGenMTwist::printOn ( std::ostream & s) const

Outputs a summary of self's internal state on ostream s.

◆ restart() [1/2]

void RWRandGenMTwist::restart ( )

Restarts the generator, arbitrarily seeding it by a call to the time() function.

◆ restart() [2/2]

void RWRandGenMTwist::restart ( unsigned long seed)

Restarts the generator with specified seed.

◆ restoreFrom() [1/2]

void RWRandGenMTwist::restoreFrom ( RWFile & )

Restores internal state of self from an RWFile.

◆ restoreFrom() [2/2]

void RWRandGenMTwist::restoreFrom ( RWvistream & )

Restores internal state of self from a virtual stream.

◆ saveOn() [1/2]

void RWRandGenMTwist::saveOn ( RWFile & ) const

Stores internal state of self in a binary format to an RWFile.

◆ saveOn() [2/2]

void RWRandGenMTwist::saveOn ( RWvostream & ) const

Stores internal state of self to a virtual stream.

◆ scanFrom()

void RWRandGenMTwist::scanFrom ( std::istream & s)

Inputs an internal state from istream s to self.

◆ seed()

unsigned long RWRandGenMTwist::seed ( ) const

Returns the seed used to initialize the generator.

Friends And Related Symbol Documentation

◆ operator!=()

bool operator!= ( const RWRandGenMTwist & lhs,
const RWRandGenMTwist & rhs )
related

Returns the negation of operator==().

◆ operator<<()

std::ostream & operator<< ( std::ostream & s,
const RWRandGenMTwist & gen )
related

Outputs a summary of gen's internal state on ostream s.

◆ operator==

bool operator== ( const RWRandGenMTwist & lhs,
const RWRandGenMTwist & rhs )
friend

Returns true if lhs generator is equal to rhs generator. Two distinct instances of RWRandGenMTwist are equal if they will return identical sequences of values.

◆ operator>>()

std::istream & operator>> ( std::istream & s,
RWRandGenMTwist & gen )
related

Inputs an internal state from istream s to gen.

Copyright © 2025 Rogue Wave Software, Inc., a Perforce company. All Rights Reserved.