Simbody  3.5
SimTK::Random Class Reference

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

+ Inheritance diagram for SimTK::Random:

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...
 

Public Member Functions

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

Protected Member Functions

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

Protected Attributes

RandomImpl * impl
 

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. One minor concession to threads: even if you don't set the seed explicitly, each thread's Random object will use a different seed so you'll get a unique series of numbers in each thread.

Constructor & Destructor Documentation

SimTK::Random::~Random ( )
SimTK::Random::Random ( )
protected

This constructor should never be invoked directly.

Instead, create an instance of one of the subclasses.

Member Function Documentation

void SimTK::Random::setSeed ( int  seed)

Reinitialize this random number generator with a new seed value.

Real SimTK::Random::getValue ( ) const

Get the next value in the pseudo-random sequence.

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

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

RandomImpl& SimTK::Random::getImpl ( )
protected

Get the internal object which implements the random number generator.

const RandomImpl& SimTK::Random::getConstImpl ( ) const
protected

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

Member Data Documentation

RandomImpl* SimTK::Random::impl
protected

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