|
This is a class that generates random numbers i.e. named the Random Number Generator (RNG). More...
#include <RNG.h>
Public Member Functions | |
RNG () | |
default constructor More... | |
void | setRandomSeed (unsigned long int new_seed) |
This is the seed for the random number generator (note the call to seed_LFG is only required really if using that type of generator, but the other one is always required) More... | |
void | read (std::istream &is) |
void | write (std::ostream &os) const |
Mdouble | getRandomNumber () |
This is a random generating routine can be used for initial positions. More... | |
Mdouble | getRandomNumber (Mdouble min, Mdouble max) |
Mdouble | operator() (Mdouble min, Mdouble max) |
Shorthand for getRandomNumber(min, max) More... | |
Mdouble | operator() () |
Mdouble | getNormalVariate () |
Produces a random number according to a normal distribution with mean 0 and standard deviation 1. More... | |
Mdouble | getNormalVariate (Mdouble mean, Mdouble stdev) |
Produces a random number according to a normal distribution. More... | |
unsigned int | getPoissonVariate (Mdouble lambda) |
Produces a random number according to a Poisson distribution. More... | |
Mdouble | test () |
This function tests the quality of random numbers, based on the chi-squared test. More... | |
void | setLinearCongruentialGeneratorParmeters (const unsigned int a, const unsigned int c, unsigned int m) |
This functions set the parameters for the LCG random number generator. It goes multiplier, addition, mod. More... | |
void | randomise () |
sets the random variables such that they differ for each run More... | |
void | setLaggedFibonacciGeneratorParameters (const unsigned int p, const unsigned int q) |
This function sets the parameters for the LFG random number generator. More... | |
void | setRandomNumberGenerator (RNGType type) |
Allows the user to set which random number generator is used. More... | |
Private Member Functions | |
Mdouble | getRandomNumberFromLinearCongruentialGenerator (Mdouble min, Mdouble max) |
This is a basic Linear Congruential Generator Random. More... | |
Mdouble | getRandomNumberFromLaggedFibonacciGenerator (Mdouble min, Mdouble max) |
This is a Lagged Fibonacci Generator. More... | |
void | seedLaggedFibonacciGenerator () |
This seed the LFG. More... | |
Private Attributes | |
unsigned long int | randomSeedLinearCongruentialGenerator_ |
This is the initial seed of the RNG. More... | |
std::vector< Mdouble > | randomSeedLaggedFibonacciGenerator_ |
This is the seeds required for the LFG. More... | |
unsigned long int | a_ |
This are the two parameters that control the LCG random generated. More... | |
unsigned long int | c_ |
unsigned long int | m_ |
unsigned long int | p_ |
This are the parameters that control the LFG random generator. More... | |
unsigned long int | q_ |
RNGType | type_ |
This is the type of random number generator. More... | |
bool | haveSavedBoxMuller_ |
A flag that keeps track of whether or not to generate a new pair of normal variates (using Box–Muller) More... | |
Mdouble | savedBoxMuller_ |
A storage space for the so-far-unused variate from the pair generated by Box–Muller. More... | |
This is a class that generates random numbers i.e. named the Random Number Generator (RNG).
This is a stand-along class; but is encapsulated (used) by the MD class. To make it architecture safe the both LCG and function is hard codes i.e. does not use the internal C++ one.
RNG::RNG | ( | ) |
default constructor
This is a random number generator and returns a Mdouble within the range specified
References a_, c_, haveSavedBoxMuller_, LAGGED_FIBONACCI_GENERATOR, m_, p_, q_, randomSeedLaggedFibonacciGenerator_, randomSeedLinearCongruentialGenerator_, savedBoxMuller_, seedLaggedFibonacciGenerator(), and type_.
Mdouble RNG::getNormalVariate | ( | ) |
Produces a random number according to a normal distribution with mean 0 and standard deviation 1.
References mathsFunc::cos(), getRandomNumber(), haveSavedBoxMuller_, mathsFunc::log(), constants::pi, savedBoxMuller_, and mathsFunc::sin().
Referenced by getNormalVariate().
Produces a random number according to a normal distribution.
References ERROR, getNormalVariate(), logger, and WARN.
unsigned int RNG::getPoissonVariate | ( | Mdouble | lambda | ) |
Produces a random number according to a Poisson distribution.
This uses Knuth's algorithm for generating Poisson variates. It's simple but slow for large values of lambda — beware.
References mathsFunc::exp(), getRandomNumber(), logger, and WARN.
Referenced by CurvyChute::createBottom().
Mdouble RNG::getRandomNumber | ( | ) |
This is a random generating routine can be used for initial positions.
Referenced by SmoothChute::actionsBeforeTimeStep(), Chutebelt::actionsOnRestart(), NautaMixer::addParticles(), HeaterBoundary::checkBoundaryAfterParticleMoved(), BaseCluster::computeInternalStructure(), LawinenBox::create_inflow_particle(), ChutePeriodic::create_inflow_particle(), ChuteWithContraction::create_inflow_particle(), Funnel::create_inflow_particle(), AngleOfRepose::create_inflow_particle(), FlowRule::create_inflow_particle(), SilbertPeriodic::create_inflow_particle(), SegregationWithHopper::create_inflow_particle(), Slide::create_rough_wall(), Chute::createBottom(), CurvyChute::createBottom(), Chute::createFlowParticle(), PSD::drawSample(), InsertionBoundary::generateParticle(), BidisperseCubeInsertionBoundary::generateParticle(), PolydisperseInsertionBoundary::generateParticle(), getNormalVariate(), getPoissonVariate(), InitialConditions< SpeciesType >::InitialConditions(), HorizontalMixer::introduceParticlesInDomain(), main(), operator()(), BaseCluster::particleInsertionSuccessful(), particleParticleTest(), FixedClusterInsertionBoundary::placeParticle(), ChuteInsertionBoundary::placeParticle(), CubeInsertionBoundary::placeParticle(), HopperInsertionBoundary::placeParticle(), PolydisperseInsertionBoundary::placeParticle(), RandomClusterInsertionBoundary::placeParticle(), MD_demo::RandomRadius(), DPMBase::setMeanVelocityAndKineticEnergy(), BaseCluster::setRadii(), ClosedCSCWalls::setupInitialConditions(), CSCInit::setupInitialConditions(), CSCWalls::setupInitialConditions(), MercuryLogo::setupInitialConditions(), SmoothChute::setupInitialConditions(), NozzleDemo::setupInitialConditions(), Binary::setupInitialConditions(), FreeCooling2DinWallsDemo::setupInitialConditions(), FreeCooling3DDemoProblem::setupInitialConditions(), FreeCooling3DinWallsDemo::setupInitialConditions(), FreeCoolingDemoProblem::setupInitialConditions(), HourGlass2D::setupInitialConditions(), HourGlass::setupInitialConditions(), MinimalExampleDrum::setupInitialConditions(), TimeDependentPeriodicBoundary3DSelfTest::setupInitialConditions(), FiveParticles::setupInitialConditions(), Cstatic2d::setupInitialConditions(), LeesEdwardsSelfTest::setupInitialConditions(), NozzleSelfTest::setupInitialConditions(), ParticleCreation::setupInitialConditions(), ParticleParticleCollision::setupInitialConditions(), WallParticleCollision::setupInitialConditions(), my_problem_HGRID::setupInitialConditions(), TriangulatedScrewSelfTest::setupInitialConditions(), TriangulatedWallSelfTest::setupInitialConditions(), DrumRot::setupInitialConditions(), RotatingDrum::setupInitialConditions(), ScalingTestInitialConditionsRelax::setupInitialConditions(), GranularCollapse::setupInitialConditions(), EllipticalSuperQuadricCollision::setupInitialConditions(), Tutorial11::setupInitialConditions(), MD_demo::setupInitialConditions(), MpiMaserChuteTest::setupInitialConditions(), MpiPeriodicBoundaryUnitTest::setupInitialConditions(), ChuteBottom::setupInitialConditions(), test(), and wallParticleTest().
References getRandomNumberFromLaggedFibonacciGenerator(), getRandomNumberFromLinearCongruentialGenerator(), LINEAR_CONGRUENTIAL_GENERATOR, logger, and type_.
This is a Lagged Fibonacci Generator.
This is a basic Linear Fibonacci Generator Random Is described by three parameters, the multiplication a, the addition c and the mod m
References p_, q_, and randomSeedLaggedFibonacciGenerator_.
Referenced by getRandomNumber().
This is a basic Linear Congruential Generator Random.
This is a basic Linear Congruential Generator Random Is described by three parameters, the multiplication a, the addition c and the mod m
References a_, c_, m_, and randomSeedLinearCongruentialGenerator_.
Referenced by getRandomNumber(), and seedLaggedFibonacciGenerator().
|
inline |
References getRandomNumber().
Shorthand for getRandomNumber(min, max)
References getRandomNumber().
void RNG::randomise | ( | ) |
sets the random variables such that they differ for each run
References a_, MPIContainer::broadcast(), c_, MPIContainer::Instance(), m_, p_, PROCESSOR_ID, q_, randomSeedLinearCongruentialGenerator_, seedLaggedFibonacciGenerator(), setRandomSeed(), and type_.
Referenced by FixedClusterInsertionBoundary::checkBoundaryBeforeTimeStep(), RandomClusterInsertionBoundary::checkBoundaryBeforeTimeStep(), LawinenBox::LawinenBox(), main(), FixedClusterInsertionBoundary::placeParticle(), RandomClusterInsertionBoundary::placeParticle(), and DPMBase::readNextArgument().
void RNG::read | ( | std::istream & | is | ) |
References a_, c_, m_, p_, q_, randomSeedLinearCongruentialGenerator_, seedLaggedFibonacciGenerator(), and type_.
Referenced by DPMBase::read().
|
private |
This seed the LFG.
References getRandomNumberFromLinearCongruentialGenerator(), constants::i, p_, and randomSeedLaggedFibonacciGenerator_.
Referenced by randomise(), read(), RNG(), setLaggedFibonacciGeneratorParameters(), and setRandomSeed().
void RNG::setLaggedFibonacciGeneratorParameters | ( | const unsigned int | p, |
const unsigned int | q | ||
) |
This function sets the parameters for the LFG random number generator.
References p_, q_, randomSeedLaggedFibonacciGenerator_, and seedLaggedFibonacciGenerator().
void RNG::setLinearCongruentialGeneratorParmeters | ( | const unsigned int | a, |
const unsigned int | c, | ||
unsigned int | m | ||
) |
void RNG::setRandomNumberGenerator | ( | RNGType | type | ) |
void RNG::setRandomSeed | ( | unsigned long int | new_seed | ) |
This is the seed for the random number generator (note the call to seed_LFG is only required really if using that type of generator, but the other one is always required)
References randomSeedLinearCongruentialGenerator_, and seedLaggedFibonacciGenerator().
Referenced by DPMBase::constructor(), main(), particleParticleTest(), PSD::PSD(), randomise(), and PSD::setFixedSeed().
Mdouble RNG::test | ( | ) |
This function tests the quality of random numbers, based on the chi-squared test.
This function tests the quality of random numbers, based on the chi-squared test. It reports a probability that the random number being generated are coming from a uniform distributed. If this number is less than 0.95, it is strongly advised that you change the parameters being used
References mathsFunc::chi_squared_prob(), getRandomNumber(), constants::i, INFO, logger, and NO_FLUSH.
Referenced by main().
void RNG::write | ( | std::ostream & | os | ) | const |
References a_, c_, m_, p_, q_, randomSeedLinearCongruentialGenerator_, and type_.
Referenced by DPMBase::write().
|
private |
This are the two parameters that control the LCG random generated.
Referenced by getRandomNumberFromLinearCongruentialGenerator(), randomise(), read(), RNG(), setLinearCongruentialGeneratorParmeters(), and write().
|
private |
|
private |
A flag that keeps track of whether or not to generate a new pair of normal variates (using Box–Muller)
Referenced by getNormalVariate(), and RNG().
|
private |
|
private |
This are the parameters that control the LFG random generator.
Referenced by getRandomNumberFromLaggedFibonacciGenerator(), randomise(), read(), RNG(), seedLaggedFibonacciGenerator(), setLaggedFibonacciGeneratorParameters(), and write().
|
private |
Referenced by getRandomNumberFromLaggedFibonacciGenerator(), randomise(), read(), RNG(), setLaggedFibonacciGeneratorParameters(), and write().
|
private |
This is the seeds required for the LFG.
Referenced by getRandomNumberFromLaggedFibonacciGenerator(), RNG(), seedLaggedFibonacciGenerator(), and setLaggedFibonacciGeneratorParameters().
|
private |
This is the initial seed of the RNG.
Referenced by getRandomNumberFromLinearCongruentialGenerator(), randomise(), read(), RNG(), setRandomSeed(), and write().
|
private |
A storage space for the so-far-unused variate from the pair generated by Box–Muller.
Referenced by getNormalVariate(), and RNG().
|
private |
This is the type of random number generator.
Referenced by getRandomNumber(), randomise(), read(), RNG(), setRandomNumberGenerator(), and write().