Logo ROOT   6.12/07
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.
51  For example, when `SkipNumber = 2`, the generator will have two extra iterations that will be discarder.
52 
53  * MIXMAX with N = 240. This is a new version of the generator (version 2.0beta) described in the
54  <a href="http://dx.doi.org/10.1016/j.chaos.2016.05.003">2016 paper</a> (3rd reference), with
55  special number $s=487013230256099140$, $m=2^{51}+1$ and having a period of $10^{4389}$.
56 
57  * MIXMAX with N = 17, from the 2.0beta version with $s=0$ and $m=2^{36}+1$. The period of the generator is $10^{294}$.
58 
59  * MIXMAX with N = 256 from the 1.0 version. The period is (for `SkipNumber=0`) $10^{4682}$.
60  For this generator we recommend in ROOT using a default value of `SkipNumber=2, while for the previous two generators
61  skipping is not needed.
62 
63  This table describes the properties of the MIXMAX generators. MIXMAX is a genuine 61 bit generator on the Galois field GF[p], where
64  $p=2^{61}-1$ is the Mersenne prime number.
65  The MIXMAX generators with these parameters pass all of the BigCrush
66  tests in the <a href="http://simul.iro.umontreal.ca/testu01/tu01.html">TestU01 suite</a>.
67 
68 \latexonly
69  \begin{table}[h]
70  \centering
71  \begin{tabular}{@{} rrlcrr @{}}
72 
73  \toprule
74  Dimension &~ Entropy & Decorrelation Time & Iteration Time & Relaxation Time &Period q\\
75  N &~~ $~h(T)$ &~~~ $\tau_0 = {1\over h(T) 2N }$ & t & $\tau ={1\over h(T) \ln {1\over \delta v_0}}$ & $ \log_{10} (q)$ \\ % Crush
76  \midrule
77  256 & 194 & ~~~~~0.000012 & 1 & 95.00 & 4682\footnote{full
78  period is not confirmed} \\
79  \hline
80  8 & 220 & $~~~~~0.00028$ & 1 & 1.54 & 129 \\
81  17 & 374 & ~~~~~0.000079 & 1 & 1.92 & 294 \\
82  240 & 8679 & ~~~~~0.00000024 & 1 & 1.17 & 4389 \\
83  \bottomrule
84  \end{tabular}
85  \caption{The entropy $h(T)$, decorrelation time $\tau_0$
86  decorrelation time, relaxation time $\tau $ and period of the MIXMAX generator
87  \cite{savvidy2017ex,savvidy2017cl},
88  expressed in units of the iteration time $t$, which is
89  normalised to 1.
90  Clearly $\tau_0~ < t ~< \tau $.
91 }
92 \end{table}
93 \endlatexonly
94 
95  The References for MIXMAX are
96 
97  * G.K.Savvidy and N.G.Ter-Arutyunian, *On the Monte Carlo simulation of physical systems,
98  J.Comput.Phys. 97, 566 (1991)*;
99  Preprint EPI-865-16-86, Yerevan, Jan. 1986
100 
101  * K.Savvidy, *The MIXMAX random number generator*,
102  Comp. Phys. Commun. 196 (2015), pp 161–165
103  http://dx.doi.org/10.1016/j.cpc.2015.06.003
104 
105  * K.Savvidy and G.Savvidy, *Spectrum and Entropy of C-systems MIXMAX Random Number Generator*,
106  Chaos, Solitons & Fractals, Volume 91, (2016) pp. 33–38
107  http://dx.doi.org/10.1016/j.chaos.2016.05.003
108 
109 
110  @ingroup Random
111  */
112 
113  template<int N, int SkipNumber>
114  class MixMaxEngine : public TRandomEngine {
115 
116  public:
117 
119 
120  // this should be changed for WINDOWS
121 #ifndef __LP64__
122  typedef uint64_t StateInt_t;
123 #else
124  typedef unsigned long long StateInt_t;
125 #endif
126  typedef uint64_t Result_t;
127 
128 
129  MixMaxEngine(uint64_t seed=1);
130 
131  virtual ~MixMaxEngine();
132 
133 
134  /// Get the size of the generator
135  static int Size();
136 
137  /// maximum integer that can be generated. For MIXMAX is 2^61-1
138  static uint64_t MaxInt();
139 
140  /// minimum integer that can be generated. For MIXMAX is 0
141  static uint64_t MinInt();
142 
143  /// set the generator seed
144  void SetSeed(Result_t seed);
145 
146  // generate a random number (virtual interface)
147  virtual double Rndm() { return Rndm_impl(); }
148 
149  /// generate a double random number (faster interface)
150  inline double operator() () { return Rndm_impl(); }
151 
152  /// generate an array of random numbers
153  void RndmArray (int n, double * array);
154 
155  /// generate a 64 bit integer number
156  Result_t IntRndm();
157 
158  /// get name of the generator
159  static std::string Name();
160 
161  protected:
162  // protected functions used for tesing the generator
163 
164  /// get the state of the generator
165  void GetState(std::vector<StateInt_t> & state) const;
166 
167 
168  ///set the full initial generator state
169  void SetState(const std::vector<StateInt_t> & state);
170 
171  /// Get the counter (between 0 and Size-1)
172  int Counter() const;
173 
174 
175  private:
176 
177  /// implementation function to generate the random number
178  double Rndm_impl();
179 
180  //rng_state_t * fRngState; // mix-max generator state
181  //mixmax::mixmax_engine<N> * fRng; // mixmax internal engine class
182  MixMaxEngineImpl<N> * fRng; // mixmax internal engine class
183 
184  };
185 
189 
190  extern template class MixMaxEngine<240,0>;
191  extern template class MixMaxEngine<256,0>;
192  extern template class MixMaxEngine<256,2>;
193  extern template class MixMaxEngine<256,4>;
194  extern template class MixMaxEngine<17,0>;
195  extern template class MixMaxEngine<17,1>;
196  extern template class MixMaxEngine<17,2>;
197 
198  } // end namespace Math
199 
200 } // end namespace ROOT
201 
202 
203 #include "Math/MixMaxEngine.icc"
204 
205 #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:147
static uint64_t MinInt()
minimum integer that can be generated. For MIXMAX is 0
MixMaxEngine< 256, 2 > MixMaxEngine256
Definition: MixMaxEngine.h:187
MixMaxEngineImpl< N > * fRng
Definition: MixMaxEngine.h:182
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:114
int Counter() const
Get the counter (between 0 and Size-1)
double operator()()
generate a double random number (faster interface)
Definition: MixMaxEngine.h:150
static int Size()
Get the size of the generator.
MixMaxEngine< 240, 0 > MixMaxEngine240
Definition: MixMaxEngine.h:186
Result_t IntRndm()
generate a 64 bit integer number
MixMaxEngine< 17, 0 > MixMaxEngine17
Definition: MixMaxEngine.h:188
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