RNG.h
Go to the documentation of this file.
1 // This file is part of the MercuryDPM project (https://www.mercurydpm.org).
2 // Copyright (c), The MercuryDPM Developers Team. All rights reserved.
3 // License: BSD 3-Clause License; see the LICENSE file in the root directory.
4 
5 #ifndef MECURYDPM_RNG_H
6 #define MECURYDPM_RNG_H
7 
8 //Used by the randomise function
9 #include <ctime>
10 #include <cmath>
11 #include <vector>
12 #include "ExtendedMath.h"
13 
17 enum class RNGType : unsigned char
18 {
21 };
22 
31 class RNG
32 {
33 public:
37  RNG();
38 
43  void setRandomSeed(unsigned long int new_seed);
44 
45  void read(std::istream& is);
46 
47  void write(std::ostream& os) const;
48 
53 
55 
60  {
61  return getRandomNumber(min, max);
62  }
63 
64  /*
65  * \brief Shorthand for getRandomNumber()
66  */
68  {
69  return getRandomNumber(0.0, 1.0);
70  }
71 
77 
82 
86  unsigned int getPoissonVariate(Mdouble lambda);
87 
91  Mdouble test();
92 
96  void setLinearCongruentialGeneratorParmeters(const unsigned int a, const unsigned int c, unsigned int m);
97 
101  void randomise();
102 
106  void setLaggedFibonacciGeneratorParameters(const unsigned int p, const unsigned int q);
107 
112 
113 private:
114 
119 
124 
129 
134 
139 
143  unsigned long int a_, c_, m_;
144 
148  unsigned long int p_, q_;
149 
154 
155  /*
156  * \todo JMFT: These Box--Muller private variables are currently not
157  * read/write from .restart files. This leads to undefined (unrepeatable)
158  * behaviour when restarting if you use normal variates.
159  */
160 
165 
170 
171 };
172 
173 #endif
cout<< "The eigenvalues of A are:"<< endl<< ces.eigenvalues()<< endl;cout<< "The matrix of eigenvectors, V, is:"<< endl<< ces.eigenvectors()<< endl<< endl;complex< float > lambda
Definition: ComplexEigenSolver_compute.cpp:9
double Mdouble
Definition: GeneralDefine.h:13
RNGType
Definition: RNG.h:18
@ LAGGED_FIBONACCI_GENERATOR
@ LINEAR_CONGRUENTIAL_GENERATOR
float * p
Definition: Tutorial_Map_using.cpp:9
This is a class that generates random numbers i.e. named the Random Number Generator (RNG).
Definition: RNG.h:32
RNG()
default constructor
Definition: RNG.cc:15
unsigned long int m_
Definition: RNG.h:143
unsigned long int q_
Definition: RNG.h:148
unsigned int getPoissonVariate(Mdouble lambda)
Produces a random number according to a Poisson distribution.
Definition: RNG.cc:192
void read(std::istream &is)
Definition: RNG.cc:38
Mdouble savedBoxMuller_
A storage space for the so-far-unused variate from the pair generated by Box–Muller.
Definition: RNG.h:169
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...
Definition: RNG.cc:32
Mdouble getRandomNumberFromLinearCongruentialGenerator(Mdouble min, Mdouble max)
This is a basic Linear Congruential Generator Random.
Definition: RNG.cc:214
unsigned long int randomSeedLinearCongruentialGenerator_
This is the initial seed of the RNG.
Definition: RNG.h:133
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,...
Definition: RNG.cc:71
unsigned long int c_
Definition: RNG.h:143
Mdouble test()
This function tests the quality of random numbers, based on the chi-squared test.
Definition: RNG.cc:269
void write(std::ostream &os) const
Definition: RNG.cc:58
RNGType type_
This is the type of random number generator.
Definition: RNG.h:153
unsigned long int a_
This are the two parameters that control the LCG random generated.
Definition: RNG.h:143
bool haveSavedBoxMuller_
A flag that keeps track of whether or not to generate a new pair of normal variates (using Box–Muller...
Definition: RNG.h:164
Mdouble getNormalVariate()
Produces a random number according to a normal distribution with mean 0 and standard deviation 1.
Definition: RNG.cc:144
Mdouble getRandomNumber()
This is a random generating routine can be used for initial positions.
Definition: RNG.cc:123
Mdouble operator()()
Definition: RNG.h:67
void seedLaggedFibonacciGenerator()
This seed the LFG.
Definition: RNG.cc:233
unsigned long int p_
This are the parameters that control the LFG random generator.
Definition: RNG.h:148
void setLaggedFibonacciGeneratorParameters(const unsigned int p, const unsigned int q)
This function sets the parameters for the LFG random number generator.
Definition: RNG.cc:318
Mdouble getRandomNumberFromLaggedFibonacciGenerator(Mdouble min, Mdouble max)
This is a Lagged Fibonacci Generator.
Definition: RNG.cc:245
std::vector< Mdouble > randomSeedLaggedFibonacciGenerator_
This is the seeds required for the LFG.
Definition: RNG.h:138
void randomise()
sets the random variables such that they differ for each run
Definition: RNG.cc:78
Mdouble operator()(Mdouble min, Mdouble max)
Shorthand for getRandomNumber(min, max)
Definition: RNG.h:59
void setRandomNumberGenerator(RNGType type)
Allows the user to set which random number generator is used.
Definition: RNG.cc:118
#define min(a, b)
Definition: datatypes.h:22
#define max(a, b)
Definition: datatypes.h:23
const Scalar * a
Definition: level2_cplx_impl.h:32
int * m
Definition: level2_cplx_impl.h:294
EIGEN_DEVICE_FUNC const Scalar & q
Definition: SpecialFunctionsImpl.h:2019
int c
Definition: calibrate.py:100
type
Definition: compute_granudrum_aor.py:141