MercuryDPM  Alpha
 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 : unsigned char
39 {
42 };
43 
52 class RNG
53 {
54 public:
58  RNG();
59 
64  void setRandomSeed(unsigned long int new_seed);
65 
66  void read(std::istream& is);
67 
68  void write(std::ostream& os) const;
69 
74 
76  {
77  return getRandomNumber(min, max);
78  }
79 
81  {
82  return getRandomNumber(0.0, 1.0);
83  }
84 
88  Mdouble test();
89 
93  void setLinearCongruentialGeneratorParmeters(unsigned const int a, unsigned const int c, unsigned const int m);
94 
98  void randomise();
99 
103  void setLaggedFibonacciGeneratorParameters(const unsigned int p, const unsigned int q);
104 
109 
110 private:
111 
116 
121 
126 
131 
136 
140  unsigned long int a_, c_, m_;
141 
145  unsigned long int p_, q_;
146 
151 
152 };
153 
154 #endif
void read(std::istream &is)
Definition: RNG.cc:52
unsigned long int c_
Definition: RNG.h:140
Mdouble getRandomNumberFromLaggedFibonacciGenerator(Mdouble min, Mdouble max)
This is a Lagged Fibonacci Generator.
Definition: RNG.cc:147
void seedLaggedFibonacciGenerator()
This seed the LFG.
Definition: RNG.cc:135
unsigned long int q_
Definition: RNG.h:145
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:220
void randomise()
sets the random variables such that they differ for each run
Definition: RNG.cc:91
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:84
void write(std::ostream &os) const
Definition: RNG.cc:71
Mdouble getRandomNumberFromLinearCongruentialGenerator(Mdouble min, Mdouble max)
This is a basic Linear Congruential Generator Random.
Definition: RNG.cc:115
Mdouble operator()()
Definition: RNG.h:80
unsigned long int randomSeedLinearCongruentialGenerator_
This is the initial seed of the RNG.
Definition: RNG.h:130
unsigned long int p_
This are the parameters that control the LFG random generator.
Definition: RNG.h:145
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:172
std::vector< Mdouble > randomSeedLaggedFibonacciGenerator_
This is the seeds required for the LFG.
Definition: RNG.h:135
unsigned long int a_
This are the two parameters that control the LCG random generated.
Definition: RNG.h:140
void setRandomNumberGenerator(RNGType type)
Allows the user to set which random number generator is used.
Definition: RNG.cc:96
RNGType
Definition: RNG.h:38
RNGType type_
This is the type of random number generator.
Definition: RNG.h:150
Mdouble operator()(Mdouble min, Mdouble max)
Definition: RNG.h:75
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:101
unsigned long int m_
Definition: RNG.h:140