41 m_ = 1024 * 1024 * 1024;
80 os <<
" " <<
static_cast<unsigned int>(
type_);
100 #ifdef MERCURY_USE_MPI
104 setRandomSeed(static_cast<unsigned long int>(time(
nullptr)));
108 std::vector<int> values(7);
111 values[0] =
static_cast<unsigned int>(
type_);
134 setRandomSeed(static_cast<unsigned long int>(time(
nullptr)));
150 logger.assert_debug(min <= max,
"getRandomNumber: min cannot be larger than max");
166 static const double epsilon = std::numeric_limits<Mdouble>::min();
183 }
while (radius <= epsilon);
189 return sqrt(-2.0 *
log(radius)) *
cos(theta);
197 "[RNG::getNormalVariate(Mdouble, Mdouble)] Zero stdev?");
199 }
else if (stdev < 0) {
201 "[RNG::getNormalVariate(Mdouble, Mdouble)] Negative stdev is not allowed.");
215 logger(
WARN,
"[RNG::getPoissonVariate(Mdouble)] Knuth's algorithm for Poissons may be slow for lambda = %", lambda);
226 while (u >
exp(-lambda));
234 #pragma optimize( "", off )
247 #pragma optimize( "", on )
256 for (
unsigned int i = 0;
i <
p_;
i++)
268 #pragma optimize( "", off )
270 static_cast<Mdouble>(1.0));
280 random_num = min + range * new_seed;
282 #pragma optimize( "", on )
293 static unsigned int num_of_tests = 100000;
294 static Mdouble max_num = 100.0;
295 static unsigned int num_of_bins = 10;
300 unsigned int bin = 0;
302 std::vector<int> count;
303 count.resize(num_of_bins);
306 for (
unsigned int i = 0;
i < num_of_bins;
i++)
312 for (
unsigned int i = 0;
i < num_of_tests;
i++)
315 bin =
static_cast<unsigned int>(std::floor(rn * num_of_bins / max_num));
324 Mdouble expected = num_of_tests / num_of_bins;
326 for (
unsigned int i = 0;
i < num_of_bins;
i++)
328 chi_cum = chi_cum + (count[
i] - expected) * (count[
i] - expected) / expected;
static MPIContainer & Instance()
fetch the instance to be used for communication
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.
void read(std::istream &is)
Mdouble getRandomNumberFromLaggedFibonacciGenerator(Mdouble min, Mdouble max)
This is a Lagged Fibonacci Generator.
Logger< MERCURY_LOGLEVEL > logger("MercuryKernel")
Definition of different loggers with certain modules. A user can define its own custom logger here...
void seedLaggedFibonacciGenerator()
This seed the LFG.
Mdouble exp(Mdouble Exponent)
const std::complex< Mdouble > i
void setLaggedFibonacciGeneratorParameters(const unsigned int p, const unsigned int q)
This function sets the parameters for the LFG random number generator.
Mdouble getRandomNumber()
This is a random generating routine can be used for initial positions.
unsigned int getPoissonVariate(Mdouble lambda)
Produces a random number according to a Poisson distribution.
Mdouble log(Mdouble Power)
Mdouble chi_squared_prob(Mdouble x, unsigned int k)
This is the function which actually gives the probability back using a chi squared test...
void randomise()
sets the random variables such that they differ for each run
void write(std::ostream &os) const
Mdouble savedBoxMuller_
A storage space for the so-far-unused variate from the pair generated by Box–Muller.
Mdouble getNormalVariate()
Produces a random number according to a normal distribution with mean 0 and standard deviation 1...
Mdouble getRandomNumberFromLinearCongruentialGenerator(Mdouble min, Mdouble max)
This is a basic Linear Congruential Generator Random.
unsigned long int randomSeedLinearCongruentialGenerator_
This is the initial seed of the RNG.
unsigned long int p_
This are the parameters that control the LFG random generator.
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 i...
std::enable_if< std::is_scalar< T >::value, void >::type broadcast(T &t, int fromProcessor=0)
Broadcasts a scalar from the root to all other processors.
Mdouble test()
This function tests the quality of random numbers, based on the chi-squared test. ...
bool haveSavedBoxMuller_
A flag that keeps track of whether or not to generate a new pair of normal variates (using Box–Mulle...
std::vector< Mdouble > randomSeedLaggedFibonacciGenerator_
This is the seeds required for the LFG.
unsigned long int a_
This are the two parameters that control the LCG random generated.
void setRandomNumberGenerator(RNGType type)
Allows the user to set which random number generator is used.
RNGType type_
This is the type of random number generator.