#include <RandomNumberGenerator.hpp>
Public Member Functions | |
double | StandardNormalRandomDeviate () |
double | NormalRandomDeviate (double mean, double sd) |
double | ranf () |
unsigned | randMod (unsigned base) |
void | Shuffle (unsigned num, std::vector< unsigned > &rValues) |
void | Reseed (int seed) |
Static Public Member Functions | |
static RandomNumberGenerator * | Instance () |
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 | |
int | mSeed |
unsigned | mTimesCalled |
Static Private Attributes | |
static RandomNumberGenerator * | mpInstance = NULL |
Friends | |
class | boost::serialization::access |
A special singleton class allowing one to generate different types of random number in a globally consistent way.
Definition at line 40 of file RandomNumberGenerator.hpp.
RandomNumberGenerator::RandomNumberGenerator | ( | ) | [protected] |
Protected constructor. Use Instance() to access the random number generator.
Definition at line 40 of file RandomNumberGenerator.cpp.
Referenced by Instance().
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 56 of file RandomNumberGenerator.cpp.
References mpInstance.
Referenced by AbstractCellBasedTestSuite::tearDown().
RandomNumberGenerator * RandomNumberGenerator::Instance | ( | ) | [static] |
Return a pointer to the random number generator object. The object is created the first time this method is called.
Definition at line 47 of file RandomNumberGenerator.cpp.
References mpInstance, and RandomNumberGenerator().
Referenced by TissueSimulation< DIM >::CalculateCellDivisionVector(), CryptSimulation2d::CalculateCellDivisionVector(), CryptSimulation1d::CalculateCellDivisionVector(), CryptCellsGenerator< CELL_CYCLE_MODEL >::Generate(), HoneycombMeshGenerator::GetCircularMesh(), CryptStatistics::GetCryptSection(), VertexMesh< ELEMENT_DIM, SPACE_DIM >::GetShortAxisOfElement(), TetrahedralMesh< ELEMENT_DIM, SPACE_DIM >::PermuteNodes(), RandomCellKiller< DIM >::serialize(), StochasticDurationGenerationBasedCellCycleModel::serialize(), TissueSimulation< 2 >::serialize(), StochasticWntCellCycleModel::serialize(), SimpleWntCellCycleModel::serialize(), StochasticDurationGenerationBasedCellCycleModel::SetG1Duration(), SimpleWntCellCycleModel::SetG1Duration(), StochasticWntCellCycleModel::SetG2Duration(), AbstractCellBasedTestSuite::setUp(), Shuffle(), RandomCellKiller< DIM >::TestAndLabelSingleCellForApoptosis(), and TissueSimulation< DIM >::TissueSimulation().
void RandomNumberGenerator::load | ( | Archive & | archive, | |
const unsigned int | version | |||
) | [inline, private] |
Load the RandomNumberGenerator and its member variables.
Serialization of a RandomNumberGenerator object must be done with care. Before the object is serialized via a pointer, it *MUST* be serialized directly, or an assertion will trip when a second instance of the class is created on de-serialization.
archive | the archive | |
version | the current version of this class |
Definition at line 155 of file RandomNumberGenerator.hpp.
References mSeed, and mTimesCalled.
Generate a random number from a normal distribution with given mean and standard deviation.
mean | the mean of the normal distribution from which the random number is drawn | |
sd | the standard deviation of the normal distribution from which the random number is drawn |
Definition at line 77 of file RandomNumberGenerator.cpp.
References StandardNormalRandomDeviate().
Referenced by SimpleWntCellCycleModel::SetG1Duration(), and StochasticWntCellCycleModel::SetG2Duration().
Generate a random number modulo base (ie an integer within the range 0,..,base-1),
base | the order of the field of positive integers from which the random number is drawn |
Definition at line 65 of file RandomNumberGenerator.cpp.
References mTimesCalled.
Referenced by TetrahedralMesh< ELEMENT_DIM, SPACE_DIM >::PermuteNodes(), and Shuffle().
double RandomNumberGenerator::ranf | ( | ) |
Generate a uniform random number in (0,1).
Definition at line 71 of file RandomNumberGenerator.cpp.
References mTimesCalled.
Referenced by CryptSimulation2d::ApplyTissueBoundaryConditions(), TissueSimulation< DIM >::CalculateCellDivisionVector(), CryptSimulation2d::CalculateCellDivisionVector(), CryptSimulation1d::CalculateCellDivisionVector(), CryptCellsGenerator< CELL_CYCLE_MODEL >::Generate(), HoneycombMeshGenerator::GetCircularMesh(), CryptStatistics::GetCryptSection(), VertexMesh< ELEMENT_DIM, SPACE_DIM >::GetShortAxisOfElement(), StochasticDurationGenerationBasedCellCycleModel::SetG1Duration(), StandardNormalRandomDeviate(), and RandomCellKiller< DIM >::TestAndLabelSingleCellForApoptosis().
void RandomNumberGenerator::Reseed | ( | int | seed | ) |
Reseed the random number generator.
seed | the new seed |
Definition at line 82 of file RandomNumberGenerator.cpp.
References mSeed, and mTimesCalled.
Referenced by AbstractCellBasedTestSuite::setUp().
void RandomNumberGenerator::save | ( | Archive & | archive, | |
const unsigned int | version | |||
) | const [inline, private] |
Save the RandomNumberGenerator and its member variables.
Serialization of a RandomNumberGenerator object must be done with care. Before the object is serialized via a pointer, it *MUST* be serialized directly, or an assertion will trip when a second instance of the class is created on de-serialization.
archive | the archive | |
version | the current version of this class |
Definition at line 137 of file RandomNumberGenerator.hpp.
References mSeed, and mTimesCalled.
Shuffle 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.
num | the number of integers to shuffle | |
rValues | the shuffled values |
Definition at line 89 of file RandomNumberGenerator.cpp.
References Instance(), and randMod().
double RandomNumberGenerator::StandardNormalRandomDeviate | ( | ) |
Generate a random number from the normal distribution with mean 0 and standard distribution 1.
Generate a random number from the normal distribution with mean 0 and standard distribution 1.
(STANDARD-) N O R M A L DISTRIBUTION
FOR DETAILS SEE:
AHRENS, J.H. AND DIETER, U. EXTENSIONS OF FORSYTHE'S METHOD FOR RANDOM SAMPLING FROM THE NORMAL DISTRIBUTION. MATH. COMPUT., 27,124 (OCT. 1973), 927 - 937.
ALL STATEMENT NUMBERS CORRESPOND TO THE STEPS OF ALGORITHM 'FL' (M=5) IN THE ABOVE PAPER (SLIGHTLY MODIFIED IMPLEMENTATION)
Modified by Barry W. Brown, Feb 3, 1988 to use RANF instead of SUNIF. The argument IR thus goes away.
THE DEFINITIONS OF THE CONSTANTS A(K), D(K), T(K) AND H(K) ARE ACCORDING TO THE ABOVEMENTIONED ARTICLE
Definition at line 134 of file RandomNumberGenerator.cpp.
References ranf().
Referenced by NormalRandomDeviate().
RandomNumberGenerator * RandomNumberGenerator::mpInstance = NULL [static, private] |
Pointer to the single instance.
Definition at line 122 of file RandomNumberGenerator.hpp.
Referenced by Destroy(), and Instance().
int RandomNumberGenerator::mSeed [private] |
The random number generator seed.
Definition at line 116 of file RandomNumberGenerator.hpp.
unsigned RandomNumberGenerator::mTimesCalled [private] |