MercuryDPM
Alpha
|
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 (Mdouble min, Mdouble max) |
This is a random generating routine can be used for initial positions. More... | |
Mdouble | operator() (Mdouble min, Mdouble max) |
Mdouble | operator() () |
Mdouble | test () |
This function tests the quality of random numbers, based on the chi-squared test. More... | |
void | setLinearCongruentialGeneratorParmeters (unsigned const int a, unsigned const int c, unsigned const 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... | |
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.
{Thomas: This code does sth. when min>max; I would prefer to throw an error.}
{the random seed should be stored in restart}
Definition at line 33 of file RNG.cc.
References a_, c_, LAGGED_FIBONACCI_GENERATOR, m_, p_, q_, randomSeedLaggedFibonacciGenerator_, randomSeedLinearCongruentialGenerator_, seedLaggedFibonacciGenerator(), and type_.
This is a random generating routine can be used for initial positions.
Definition at line 101 of file RNG.cc.
References getRandomNumberFromLaggedFibonacciGenerator(), getRandomNumberFromLinearCongruentialGenerator(), LAGGED_FIBONACCI_GENERATOR, LINEAR_CONGRUENTIAL_GENERATOR, and type_.
Referenced by Chute::createBottom(), ChuteInsertionBoundary::generateParticle(), CubeInsertionBoundary::generateParticle(), HopperInsertionBoundary::generateParticle(), operator()(), ChuteBottom::setupInitialConditions(), and test().
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.
Definition at line 147 of file RNG.cc.
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.
Definition at line 115 of file RNG.cc.
References a_, c_, m_, and randomSeedLinearCongruentialGenerator_.
Referenced by getRandomNumber(), and seedLaggedFibonacciGenerator().
Definition at line 75 of file RNG.h.
References getRandomNumber().
|
inline |
Definition at line 80 of file RNG.h.
References getRandomNumber().
void RNG::randomise | ( | ) |
sets the random variables such that they differ for each run
Definition at line 91 of file RNG.cc.
References setRandomSeed().
Referenced by DPMBase::readNextArgument().
void RNG::read | ( | std::istream & | is | ) |
Definition at line 52 of file RNG.cc.
References a_, c_, m_, p_, q_, randomSeedLinearCongruentialGenerator_, seedLaggedFibonacciGenerator(), and type_.
Referenced by DPMBase::read().
|
private |
This seed the LFG.
Definition at line 135 of file RNG.cc.
References getRandomNumberFromLinearCongruentialGenerator(), p_, and randomSeedLaggedFibonacciGenerator_.
Referenced by 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.
Definition at line 220 of file RNG.cc.
References p_, q_, randomSeedLaggedFibonacciGenerator_, and seedLaggedFibonacciGenerator().
void RNG::setLinearCongruentialGeneratorParmeters | ( | unsigned const int | a, |
unsigned const int | c, | ||
unsigned const 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.
Definition at line 46 of file RNG.cc.
References randomSeedLinearCongruentialGenerator_, and seedLaggedFibonacciGenerator().
Referenced by DPMBase::constructor(), and randomise().
Mdouble RNG::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
Definition at line 172 of file RNG.cc.
References mathsFunc::chi_squared_prob(), and getRandomNumber().
void RNG::write | ( | std::ostream & | os | ) | const |
Definition at line 71 of file RNG.cc.
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.
Definition at line 140 of file RNG.h.
Referenced by getRandomNumberFromLinearCongruentialGenerator(), read(), RNG(), setLinearCongruentialGeneratorParmeters(), and write().
|
private |
Definition at line 140 of file RNG.h.
Referenced by getRandomNumberFromLinearCongruentialGenerator(), read(), RNG(), setLinearCongruentialGeneratorParmeters(), and write().
|
private |
Definition at line 140 of file RNG.h.
Referenced by getRandomNumberFromLinearCongruentialGenerator(), read(), RNG(), setLinearCongruentialGeneratorParmeters(), and write().
|
private |
This are the parameters that control the LFG random generator.
Definition at line 145 of file RNG.h.
Referenced by getRandomNumberFromLaggedFibonacciGenerator(), read(), RNG(), seedLaggedFibonacciGenerator(), setLaggedFibonacciGeneratorParameters(), and write().
|
private |
Definition at line 145 of file RNG.h.
Referenced by getRandomNumberFromLaggedFibonacciGenerator(), read(), RNG(), setLaggedFibonacciGeneratorParameters(), and write().
|
private |
This is the seeds required for the LFG.
Definition at line 135 of file RNG.h.
Referenced by getRandomNumberFromLaggedFibonacciGenerator(), RNG(), seedLaggedFibonacciGenerator(), and setLaggedFibonacciGeneratorParameters().
|
private |
This is the initial seed of the RNG.
Definition at line 130 of file RNG.h.
Referenced by getRandomNumberFromLinearCongruentialGenerator(), read(), RNG(), setRandomSeed(), and write().
|
private |
This is the type of random number generator.
Definition at line 150 of file RNG.h.
Referenced by getRandomNumber(), read(), RNG(), setRandomNumberGenerator(), and write().