MercuryDPM  0.10
 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 "ExtendedMath.h"
33 
38 class RNG
39 {
40 public:
41 
42  RNG(){random_seed_LCG=0; a=1103515245; c=12345;m=1024*1024*1024;type=1;p=607;q=273;random_seed_LFG.resize(p); seed_LFG();}
43 
45  // (note the call to seed_LFG is only required really if using that type of generator, but the other one is always required
46  void set_RandomSeed(Mdouble new_seed){random_seed_LCG=new_seed; seed_LFG();}
47 
49  Mdouble get_RN(Mdouble min, Mdouble max);
50 
52  Mdouble test();
53 
55  void set_LCGParms(int new_a,int new_c,int new_m)
56  {a=new_a;c=new_c;m=new_m;}
57 
59  void randomise() {set_RandomSeed(time(NULL));}
60 
62  void set_LFGParms(int new_p, int new_q);
63 
65  void set_RNtypeLCG(){type=0;}
66 
68  void set_RNtypeLFG(){type=1;}
69 
70 private:
71 
73  Mdouble get_LCG(Mdouble min, Mdouble max);
74 
76  Mdouble get_LFG(Mdouble min, Mdouble max);
77 
79  void seed_LFG();
80 
82  unsigned long int random_seed_LCG;
83 
85  std::vector<Mdouble> random_seed_LFG;
86 
88  long int a,c,m;
89 
91  long int p,q;
92 
94  int type;
95 
96 };
97 
98 
99 #endif
void set_LFGParms(int new_p, int new_q)
This function sets the parametes for the LFG random number generator.
Definition: RNG.cc:172
long int a
This are the two parameters that control the LCG random generated.
Definition: RNG.h:88
Mdouble get_LCG(Mdouble min, Mdouble max)
This is a basic Linear Congruential Generator Random.
Definition: RNG.cc:55
Mdouble get_RN(Mdouble min, Mdouble max)
This is a random generating routine can be used for initial positions.
Definition: RNG.cc:32
long int c
Definition: RNG.h:88
long int m
Definition: RNG.h:88
void randomise()
sets the random variables such that they differ for each run
Definition: RNG.h:59
This is a class that generates random numbers i.e.
Definition: RNG.h:38
Mdouble get_LFG(Mdouble min, Mdouble max)
This is a Laggend Fibonacci Generator.
Definition: RNG.cc:89
void seed_LFG()
This seed the LFG.
Definition: RNG.cc:77
double Mdouble
Definition: ExtendedMath.h:33
int type
This is the type of random number generator.
Definition: RNG.h:94
long int q
Definition: RNG.h:91
Mdouble test()
This function tests the quality of random numbers, based on the chi-squared test. ...
Definition: RNG.cc:117
void set_LCGParms(int new_a, int new_c, int new_m)
This functions set the parameters for the LCG random number generator. It goes multiplier, addition, mod.
Definition: RNG.h:55
void set_RNtypeLCG()
Make the random number generator based on LCG.
Definition: RNG.h:65
std::vector< Mdouble > random_seed_LFG
This is the seeds required for the LFG.
Definition: RNG.h:85
void set_RNtypeLFG()
Make the random number generator based on LFG.
Definition: RNG.h:68
long int p
This are the parameters that control the LFG random generator.
Definition: RNG.h:91
unsigned long int random_seed_LCG
This is the initiall seed of the RNG.
Definition: RNG.h:82
RNG()
Definition: RNG.h:42
void set_RandomSeed(Mdouble new_seed)
This is the seed for the random number generator.
Definition: RNG.h:46