RandomNumberGenerator Class Reference

#include <RandomNumberGenerator.hpp>

Inherits SerializableSingleton< RandomNumberGenerator >.

Collaboration diagram for RandomNumberGenerator:
Collaboration graph
[legend]

List of all members.

Public Member Functions

double StandardNormalRandomDeviate ()
double NormalRandomDeviate (double mean, double stdDev)
double ranf ()
double GammaRandomDeviate (double shape, double scale)
double ExponentialRandomDeviate (double scale)
unsigned randMod (unsigned base)
template<class T >
void Shuffle (std::vector< boost::shared_ptr< T > > &rValues)
void Shuffle (unsigned num, std::vector< unsigned > &rValues)
void Reseed (unsigned seed)

Static Public Member Functions

static RandomNumberGeneratorInstance ()
static void Destroy ()

Protected Member Functions

 RandomNumberGenerator ()

Private Member Functions

template<class Archive >
void save (Archive &archive, const unsigned int version) const
template<class Archive >
void load (Archive &archive, const unsigned int version)

Private Attributes

boost::mt19937 mMersenneTwisterGenerator
boost::variate_generator
< boost::mt19937
&, boost::uniform_real<> > 
mGenerateUnitReal
boost::variate_generator
< boost::mt19937
&, boost::random::normal_distribution_v156<> > 
mGenerateStandardNormal

Static Private Attributes

static RandomNumberGeneratormpInstance = NULL

Friends

class boost::serialization::access

Detailed Description

A special singleton class allowing one to generate different types of random number in a globally consistent way.

Definition at line 59 of file RandomNumberGenerator.hpp.


Constructor & Destructor Documentation

RandomNumberGenerator::RandomNumberGenerator (  )  [protected]

Protected constructor. Use Instance() to access the random number generator.

Definition at line 41 of file RandomNumberGenerator.cpp.

References mpInstance.

Referenced by Instance().


Member Function Documentation

void RandomNumberGenerator::Destroy (  )  [static]

Destroy the current instance of the random number generator. The next call to Instance will create a new instance and re-seed. This method *must* be called before program exit, to avoid a memory leak.

Definition at line 62 of file RandomNumberGenerator.cpp.

References mpInstance.

Referenced by AbstractCellBasedTestSuite::tearDown().

double RandomNumberGenerator::ExponentialRandomDeviate ( double  scale  ) 
Returns:
Generate a random number from an exponential distribution with specified scale parameter.
Parameters:
scale The scale parameter of the exponential distribution from which the random number is drawn, often named lambda

Definition at line 133 of file RandomNumberGenerator.cpp.

References mMersenneTwisterGenerator.

Referenced by ExponentiallyDistributedStochasticDurationGenerationBasedCellCycleModel::SetG1Duration().

double RandomNumberGenerator::GammaRandomDeviate ( double  shape,
double  scale 
)
Returns:
Generate a random number from a gamma distribution with specified shape and scale parameters.
Parameters:
shape the shape parameter of the gamma distribution from which the random number is drawn
scale the scale parameter of the gamma distribution from which the random number is drawn

Definition at line 125 of file RandomNumberGenerator.cpp.

References mMersenneTwisterGenerator.

Referenced by GammaDistributedStochasticDurationCellCycleModel::SetG1Duration().

RandomNumberGenerator * RandomNumberGenerator::Instance (  )  [static]
Returns:
a pointer to the random number generator object. The object is created the first time this method is called.

Definition at line 53 of file RandomNumberGenerator.cpp.

References mpInstance, and RandomNumberGenerator().

Referenced by AbstractCellBasedSimulation< ELEMENT_DIM, SPACE_DIM >::AbstractCellBasedSimulation(), CaBasedCellPopulation< DIM >::AddCell(), DiffusionForce< DIM >::AddForceContribution(), CryptSimulation2d::CalculateCellDivisionVector(), CryptSimulation1d::CalculateCellDivisionVector(), OffLatticeSimulation< ELEMENT_DIM, SPACE_DIM >::CalculateCellDivisionVector(), RandomDirectionVertexBasedDivisionRule< SPACE_DIM >::CalculateCellDivisionVector(), RandomCellKiller< DIM >::CheckAndLabelSingleCellForApoptosis(), CryptCellsGenerator< CELL_CYCLE_MODEL >::Generate(), CellsGenerator< CELL_CYCLE_MODEL, DIM >::GenerateBasicRandom(), StochasticWntCellCycleModel::GenerateStochasticG2Duration(), StochasticOxygenBasedCellCycleModel::GenerateStochasticG2Duration(), HoneycombMeshGenerator::GetCircularMesh(), CryptStatistics::GetCryptSection(), CryptProjectionStatistics::GetCryptSection(), VertexMesh< ELEMENT_DIM, SPACE_DIM >::GetShortAxisOfElement(), CryptSimulationBoundaryCondition< DIM >::ImposeBoundaryCondition(), PlaneBoundaryCondition< DIM >::ImposeBoundaryCondition(), TetrahedralMesh< ELEMENT_DIM, SPACE_DIM >::PermuteNodes(), StochasticWntCellCycleModel::serialize(), SimpleWntCellCycleModel::serialize(), AbstractCellBasedSimulation< DIM >::serialize(), RandomCellKiller< DIM >::serialize(), StochasticOxygenBasedCellCycleModel::serialize(), StochasticDurationGenerationBasedCellCycleModel::serialize(), StochasticDurationCellCycleModel::serialize(), GammaDistributedStochasticDurationCellCycleModel::serialize(), ExponentiallyDistributedStochasticDurationGenerationBasedCellCycleModel::serialize(), SimpleWntCellCycleModel::SetG1Duration(), StochasticDurationGenerationBasedCellCycleModel::SetG1Duration(), StochasticDurationCellCycleModel::SetG1Duration(), GammaDistributedStochasticDurationCellCycleModel::SetG1Duration(), ExponentiallyDistributedStochasticDurationGenerationBasedCellCycleModel::SetG1Duration(), AbstractCellBasedTestSuite::setUp(), Shuffle(), PottsBasedCellPopulation< DIM >::UpdateCellLocations(), CaBasedCellPopulation< DIM >::UpdateCellLocations(), SimpleOxygenBasedCellCycleModel::UpdateHypoxicDuration(), and CaBasedCellPopulation< DIM >::WriteVtkResultsToFile().

template<class Archive >
void RandomNumberGenerator::load ( Archive &  archive,
const unsigned int  version 
) [inline, private]

Load the RandomNumberGenerator and its member variables.

Note:
do not serialize this singleton directly. Instead, serialize the object returned by GetSerializationWrapper().
Parameters:
archive the archive
version the current version of this class

Reimplemented from SerializableSingleton< RandomNumberGenerator >.

Definition at line 118 of file RandomNumberGenerator.hpp.

References mGenerateStandardNormal, and mMersenneTwisterGenerator.

double RandomNumberGenerator::NormalRandomDeviate ( double  mean,
double  stdDev 
)
Returns:
Generate a random number from a normal distribution with given mean and standard deviation.
Parameters:
mean the mean of the normal distribution from which the random number is drawn
stdDev the standard deviation of the normal distribution from which the random number is drawn

Definition at line 120 of file RandomNumberGenerator.cpp.

References StandardNormalRandomDeviate().

Referenced by StochasticWntCellCycleModel::GenerateStochasticG2Duration(), StochasticOxygenBasedCellCycleModel::GenerateStochasticG2Duration(), and SimpleWntCellCycleModel::SetG1Duration().

unsigned RandomNumberGenerator::randMod ( unsigned  base  ) 
Returns:
Generate a random number modulo base (i.e. an integer within the range [0, base) == [0,1,..,base-1] ).
Parameters:
base the order of the field of positive integers from which the random number is drawn. This should be no greater than INT_MAX

Definition at line 71 of file RandomNumberGenerator.cpp.

References mMersenneTwisterGenerator, and NEVER_REACHED.

Referenced by Shuffle(), and PottsBasedCellPopulation< DIM >::UpdateCellLocations().

double RandomNumberGenerator::ranf (  ) 
void RandomNumberGenerator::Reseed ( unsigned  seed  ) 

Reseed the random number generator.

Parameters:
seed the new seed

Definition at line 145 of file RandomNumberGenerator.cpp.

References mGenerateStandardNormal, mGenerateUnitReal, and mMersenneTwisterGenerator.

Referenced by AbstractCellBasedTestSuite::setUp().

template<class Archive >
void RandomNumberGenerator::save ( Archive &  archive,
const unsigned int  version 
) const [inline, private]

Save the RandomNumberGenerator and its member variables.

Note:
do not serialize this singleton directly. Instead, serialize the object returned by GetSerializationWrapper().
Parameters:
archive the archive
version the current version of this class

Reimplemented from SerializableSingleton< RandomNumberGenerator >.

Definition at line 90 of file RandomNumberGenerator.hpp.

References mGenerateStandardNormal, and mMersenneTwisterGenerator.

void RandomNumberGenerator::Shuffle ( unsigned  num,
std::vector< unsigned > &  rValues 
)

Produce a permutation of the integers 0,1,..,num-1, using the Knuth-algorithm (also called the Fisher-Yates algorithm), a linear time unbiased method. The shuffled values are returned in rValues, which doesn't need to be correctly-sized when passed in.

Parameters:
num the number of integers to shuffle
rValues the output permutation of shuffled values (any initial values ignored)

Definition at line 156 of file RandomNumberGenerator.cpp.

References Instance(), and randMod().

template<class T >
void RandomNumberGenerator::Shuffle ( std::vector< boost::shared_ptr< T > > &  rValues  )  [inline]

Produce a permutation of the integers and non-empty std::vector, using the Knuth-algorithm (also called the Fisher-Yates algorithm), a linear time unbiased method. The values are shuffled in place.

Parameters:
rValues the initial values and the output permutation of shuffled values. Must be non-empty

Definition at line 194 of file RandomNumberGenerator.hpp.

References Instance(), and randMod().

Referenced by TetrahedralMesh< ELEMENT_DIM, SPACE_DIM >::PermuteNodes(), and PottsBasedCellPopulation< DIM >::UpdateCellLocations().

double RandomNumberGenerator::StandardNormalRandomDeviate (  ) 
Returns:
a random number from the normal distribution with mean 0 and standard distribution 1.

Definition at line 115 of file RandomNumberGenerator.cpp.

References mGenerateStandardNormal.

Referenced by DiffusionForce< DIM >::AddForceContribution(), and NormalRandomDeviate().


Member Data Documentation

boost::variate_generator<boost::mt19937& , boost::random::normal_distribution_v156<> > RandomNumberGenerator::mGenerateStandardNormal [private]

An adaptor to a standard normal distribution.

Definition at line 72 of file RandomNumberGenerator.hpp.

Referenced by load(), Reseed(), save(), and StandardNormalRandomDeviate().

boost::variate_generator<boost::mt19937& , boost::uniform_real<> > RandomNumberGenerator::mGenerateUnitReal [private]

An adaptor to a unit interval distribution.

Definition at line 68 of file RandomNumberGenerator.hpp.

Referenced by ranf(), and Reseed().

The main random number generator.

Definition at line 63 of file RandomNumberGenerator.hpp.

Referenced by ExponentialRandomDeviate(), GammaRandomDeviate(), load(), randMod(), Reseed(), and save().

Pointer to the single instance.

Definition at line 77 of file RandomNumberGenerator.hpp.

Referenced by Destroy(), Instance(), and RandomNumberGenerator().


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

Generated by  doxygen 1.6.2