MercuryDPM  Beta
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
RNG.h
Go to the documentation of this file.
1 //Copyright (c) 2013-2014, The MercuryDPM Developers Team. All rights reserved.
2 //For the list of developers, see <http://www.MercuryDPM.org/Team>.
3 //
4 //Redistribution and use in source and binary forms, with or without
5 //modification, are permitted provided that the following conditions are met:
6 // * Redistributions of source code must retain the above copyright
7 // notice, this list of conditions and the following disclaimer.
8 // * Redistributions in binary form must reproduce the above copyright
9 // notice, this list of conditions and the following disclaimer in the
10 // documentation and/or other materials provided with the distribution.
11 // * Neither the name MercuryDPM nor the
12 // names of its contributors may be used to endorse or promote products
13 // derived from this software without specific prior written permission.
14 //
15 //THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
16 //ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
17 //WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
18 //DISCLAIMED. IN NO EVENT SHALL THE MERCURYDPM DEVELOPERS TEAM BE LIABLE FOR ANY
19 //DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
20 //(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
21 //LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
22 //ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
23 //(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
24 //SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
25 
26 #ifndef RNG_H
27 #define RNG_H
28 
29 //Used by the randomise function
30 #include <time.h>
31 #include <cmath>
32 #include <vector>
33 #include "ExtendedMath.h"
34 
38 enum class RNGType
39 {
42 };
43 
52 class RNG
53 {
54 public:
58  RNG();
59 
64  void setRandomSeed(unsigned long int new_seed);
65 
70 
74  Mdouble test();
75 
79  void setLinearCongruentialGeneratorParmeters(unsigned const int a, unsigned const int c, unsigned const int m);
80 
84  void randomise();
85 
89  void setLaggedFibonacciGeneratorParameters(const unsigned int p, const unsigned int q);
90 
95 
96 private:
97 
102 
107 
112 
117 
122 
126  unsigned long int a_, c_, m_;
127 
131  unsigned long int p_, q_;
132 
137 
138 };
139 
140 #endif
RNGType
Definition: RNG.h:38
unsigned long int c_
Definition: RNG.h:126
Mdouble getRandomNumberFromLaggedFibonacciGenerator(Mdouble min, Mdouble max)
This is a Lagged Fibonacci Generator.
Definition: RNG.cc:115
void seedLaggedFibonacciGenerator()
This seed the LFG.
Definition: RNG.cc:103
unsigned long int q_
Definition: RNG.h:131
double Mdouble
void setLaggedFibonacciGeneratorParameters(const unsigned int p, const unsigned int q)
This function sets the parameters for the LFG random number generator.
Definition: RNG.cc:188
void randomise()
sets the random variables such that they differ for each run
Definition: RNG.cc:59
This is a class that generates random numbers i.e. named the Random Number Generator (RNG)...
Definition: RNG.h:52
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.
Definition: RNG.cc:52
Mdouble getRandomNumberFromLinearCongruentialGenerator(Mdouble min, Mdouble max)
This is a basic Linear Congruential Generator Random.
Definition: RNG.cc:83
unsigned long int randomSeedLinearCongruentialGenerator_
This is the initial seed of the RNG.
Definition: RNG.h:116
unsigned long int p_
This are the parameters that control the LFG random generator.
Definition: RNG.h:131
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 ...
Definition: RNG.cc:46
Mdouble test()
This function tests the quality of random numbers, based on the chi-squared test. ...
Definition: RNG.cc:140
std::vector< Mdouble > randomSeedLaggedFibonacciGenerator_
This is the seeds required for the LFG.
Definition: RNG.h:121
unsigned long int a_
This are the two parameters that control the LCG random generated.
Definition: RNG.h:126
void setRandomNumberGenerator(RNGType type)
Allows the user to set which random number generator is used.
Definition: RNG.cc:64
RNGType type_
This is the type of random number generator.
Definition: RNG.h:136
RNG()
default constructor
Definition: RNG.cc:33
Mdouble getRandomNumber(Mdouble min, Mdouble max)
This is a random generating routine can be used for initial positions.
Definition: RNG.cc:69
unsigned long int m_
Definition: RNG.h:126