Logo ROOT   6.10/09
Reference Guide
MixMaxEngine.h
Go to the documentation of this file.
1 // @(#)root/mathcore:$Id$
2 // Author: L. Moneta Tue Aug 4 2015
3 
4 /**********************************************************************
5  * *
6  * Copyright (c) 2015 LCG ROOT Math Team, CERN/PH-SFT *
7  * *
8  * *
9  **********************************************************************/
10 
11 // random engines based on ROOT
12 
13 #ifndef ROOT_Math_MixMaxEngine
14 #define ROOT_Math_MixMaxEngine
15 
16 #include <cstdint>
17 #include <vector>
18 #include <string>
19 
20 #include "Math/TRandomEngine.h"
21 
22 
23 // struct rng_state_st; /// forward declare generator state
24 
25 // typedef struct rng_state_st rng_state_t;
26 
27 // namespace mixmax {
28 // template<int Ndim>
29 // class mixmax_engine;
30 // }
31 
32 namespace ROOT {
33 
34  namespace Math {
35 
36  template<int N>
38 
39  /**
40  MixMaxEngine is a wrapper class for the MIXMAX Random number generator.
41  MIXMAX is a matrix-recursive random number generator introduced by
42  G. Savvidy.
43 
44  The real implementation of the generator, written in C, is in the mixmax.h and mixmax.cxx files.
45  This generator code is available also at hepforge: http://mixmax.hepforge.org
46  The MIXMAX code has been created and developed by Konstantin Savvidy and it is
47  released under GNU Lesser General Public License v3.
48 
49  This wrapper class provides 3 different variants of MIXMAX according to the template para extra parameter N.
50  The extra parameter, `SkipNumber`, is used to perform additional iterations of the generator before returning the random numbers. For example, when `SkipNumber = 2`, the generator will have two extra iterations that will be discarder.
51 
52  * MIXMAX with N = 240. This is a new version of the generator (version 2.0) described in the 2016 paper (3rd reference), with
53  special number $s=487013230256099140$, $m=2^{51}+1$ and having a period of $10^{4389}$.
54 
55  * MIXMAX with N = 17, from the 2.0 version with $s=0$ and $m=2^{36}+1$. The period of the generator is $10^{294}$.
56 
57  * MIXMAX with N = 256 from the 1.0 version. The period is (for `SkipNumber=0`) $10^{4682}$. For this generator we recommend using a default value of `SkipNumber=2`.
58 
59 
60  The References for MIXMAX are
61 
62  * G.K.Savvidy and N.G.Ter-Arutyunian, *On the Monte Carlo simulation of physical systems,
63  J.Comput.Phys. 97, 566 (1991)*;
64  Preprint EPI-865-16-86, Yerevan, Jan. 1986
65 
66  * K.Savvidy, *The MIXMAX random number generator*,
67  Comp. Phys. Commun. 196 (2015), pp 161–165
68  http://dx.doi.org/10.1016/j.cpc.2015.06.003
69 
70  * K.Savvidy and G.Savvidy, *Spectrum and Entropy of C-systems MIXMAX Random Number Generator*,
71  Chaos, Solitons & Fractals, Volume 91, (2016) pp. 33–38
72  http://dx.doi.org/10.1016/j.chaos.2016.05.003
73 
74 
75  @ingroup Random
76  */
77 
78  template<int N, int SkipNumber>
79  class MixMaxEngine : public TRandomEngine {
80 
81  public:
82 
84 
85  // this should be changed for WINDOWS
86 #ifndef __LP64__
87  typedef uint64_t StateInt_t;
88 #else
89  typedef unsigned long long StateInt_t;
90 #endif
91  typedef uint64_t Result_t;
92 
93 
94  MixMaxEngine(uint64_t seed=1);
95 
96  virtual ~MixMaxEngine();
97 
98 
99  /// Get the size of the generator
100  static int Size();
101 
102  /// maximum integer that can be generated. For MIXMAX is 2^61-1
103  static uint64_t MaxInt();
104 
105  /// minimum integer that can be generated. For MIXMAX is 0
106  static uint64_t MinInt();
107 
108  /// set the generator seed
109  void SetSeed(Result_t seed);
110 
111  // generate a random number (virtual interface)
112  virtual double Rndm() { return Rndm_impl(); }
113 
114  /// generate a double random number (faster interface)
115  inline double operator() () { return Rndm_impl(); }
116 
117  /// generate an array of random numbers
118  void RndmArray (int n, double * array);
119 
120  /// generate a 64 bit integer number
121  Result_t IntRndm();
122 
123  /// get name of the generator
124  static std::string Name();
125 
126  protected:
127  // protected functions used for tesing the generator
128 
129  /// get the state of the generator
130  void GetState(std::vector<StateInt_t> & state) const;
131 
132 
133  ///set the full initial generator state
134  void SetState(const std::vector<StateInt_t> & state);
135 
136  /// Get the counter (between 0 and Size-1)
137  int Counter() const;
138 
139 
140  private:
141 
142  /// implementation function to generate the random number
143  double Rndm_impl();
144 
145  //rng_state_t * fRngState; // mix-max generator state
146  //mixmax::mixmax_engine<N> * fRng; // mixmax internal engine class
147  MixMaxEngineImpl<N> * fRng; // mixmax internal engine class
148 
149  };
150 
154 
155  extern template class MixMaxEngine<240,0>;
156  extern template class MixMaxEngine<256,0>;
157  extern template class MixMaxEngine<256,2>;
158  extern template class MixMaxEngine<256,4>;
159  extern template class MixMaxEngine<17,0>;
160  extern template class MixMaxEngine<17,1>;
161  extern template class MixMaxEngine<17,2>;
162 
163  } // end namespace Math
164 
165 } // end namespace ROOT
166 
167 
168 #include "Math/MixMaxEngine.icc"
169 
170 #endif /* ROOT_Math_MixMaxEngine */
static uint64_t MaxInt()
maximum integer that can be generated. For MIXMAX is 2^61-1
static std::string Name()
get name of the generator
void SetState(const std::vector< StateInt_t > &state)
set the full initial generator state
Namespace for new ROOT classes and functions.
Definition: StringConv.hxx:21
virtual double Rndm()
Definition: MixMaxEngine.h:112
static uint64_t MinInt()
minimum integer that can be generated. For MIXMAX is 0
TRandomEngine BaseType
Definition: MixMaxEngine.h:83
MixMaxEngine< 256, 2 > MixMaxEngine256
Definition: MixMaxEngine.h:152
MixMaxEngineImpl< N > * fRng
Definition: MixMaxEngine.h:147
MixMaxEngine(uint64_t seed=1)
double Rndm_impl()
implementation function to generate the random number
void SetSeed(Result_t seed)
set the generator seed
void RndmArray(int n, double *array)
generate an array of random numbers
MixMaxEngine is a wrapper class for the MIXMAX Random number generator.
Definition: MixMaxEngine.h:79
int Counter() const
Get the counter (between 0 and Size-1)
double operator()()
generate a double random number (faster interface)
Definition: MixMaxEngine.h:115
static int Size()
Get the size of the generator.
MixMaxEngine< 240, 0 > MixMaxEngine240
Definition: MixMaxEngine.h:151
Result_t IntRndm()
generate a 64 bit integer number
MixMaxEngine< 17, 0 > MixMaxEngine17
Definition: MixMaxEngine.h:153
void GetState(std::vector< StateInt_t > &state) const
get the state of the generator
Namespace for new Math classes and functions.
const Int_t n
Definition: legend1.C:16