Random Class Reference

#include <Random.h>

Inheritance diagram for Random:

Random::Gaussian Random::Uniform List of all members.

Detailed Description

This class defines the interface for pseudo-random number generators.

Subclasses generate numbers according to specific distributions. Currently, there are two such subclasses: Random::Uniform and Random::Gaussian. For example, to generate a series of pseudo-random numbers uniformly distributed between 0 and 100, you would call:

Random::Uniform random(0.0, 100.0); Real nextValue = random.getValue(); // Each time you call this, it will return a different value.

Although the numbers are distributed in a seemingly random way, they are nonetheless deterministic, so you can create several random number generators that each returns exactly the same sequence of numbers. The sequence is determined by the seed value with which the Random object is initialized. By default, a different seed is used for every object. You can invoke setSeed(int seed) on a Random object to explicitly specify the seed to use. Each seed value corresponds to a different sequence of numbers that is uncorrelated with all others.

This class is implemented using the SIMD-oriented Fast Mersenne Twister (SFMT) library. It provides good performance, excellent statistical properties, and a very long period.

The methods of this class do not provide any synchronization or other mechanism to ensure thread safety. It is therefore important that a single Random object not be accessed from multiple threads.


Public Member Functions

 ~Random ()
void setSeed (int seed)
 Reinitialize this random number generator with a new seed value.
Real getValue () const
 Get the next value in the pseudo-random sequence.
void fillArray (Real array[], int length) const
 Fill an array with values from the pseudo-random sequence.

Protected Member Functions

 Random ()
 This constructor should never be invoked directly.
RandomImpl & getImpl ()
 Get the internal object which implements the random number generator.
const RandomImpl & getConstImpl () const
 Get a constant reference to the internal object which implements the random number generator.

Protected Attributes

RandomImpl * impl

Classes

class  Gaussian
 This is a subclass of Random that generates numbers according to a Gaussian distribution with a specified mean and standard deviation. More...
class  Uniform
 This is a subclass of Random that generates numbers uniformly distributed within a specified range. More...


Constructor & Destructor Documentation

~Random (  ) 

Random (  )  [protected]

This constructor should never be invoked directly.

Instead, create an instance of one of the subclasses.


Member Function Documentation

void fillArray ( Real  array[],
int  length 
) const

Fill an array with values from the pseudo-random sequence.

const RandomImpl& getConstImpl (  )  const [protected]

Get a constant reference to the internal object which implements the random number generator.

Reimplemented in Random::Uniform, and Random::Gaussian.

RandomImpl& getImpl (  )  [protected]

Get the internal object which implements the random number generator.

Reimplemented in Random::Uniform, and Random::Gaussian.

Real getValue (  )  const

Get the next value in the pseudo-random sequence.

void setSeed ( int  seed  ) 

Reinitialize this random number generator with a new seed value.


Member Data Documentation

RandomImpl* impl [protected]


The documentation for this class was generated from the following file:
Generated on Thu Feb 28 01:34:36 2008 for SimTKcommon by  doxygen 1.4.7