Logo ROOT   6.08/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 #ifndef ROOT_Math_TRandomEngine
21 #include "Math/TRandomEngine.h"
22 #endif
23 
24 
25 // struct rng_state_st; /// forward declare generator state
26 
27 // typedef struct rng_state_st rng_state_t;
28 
29 // namespace mixmax {
30 // template<int Ndim>
31 // class mixmax_engine;
32 // }
33 
34 namespace ROOT {
35 
36  namespace Math {
37 
38  template<int N>
40 
41  /**
42  Wrapper class for the MIXMAX Random number generator.
43  It is a matrix-recursive random number generator introduced by
44  G. Savvidy.
45 
46  See the real implementation in the mixmax.h and mixmax.cxx files.
47  The generator code is available also at hepforge: http://mixmax.hepforge.org
48 
49 
50  Created by Konstantin Savvidy.
51 
52  The code is released under GNU Lesser General Public License v3
53 
54  References:
55 
56  G.K.Savvidy and N.G.Ter-Arutyunian,
57  On the Monte Carlo simulation of physical systems,
58  J.Comput.Phys. 97, 566 (1991);
59  Preprint EPI-865-16-86, Yerevan, Jan. 1986
60 
61  K.Savvidy
62  The MIXMAX random number generator
63  Comp. Phys. Commun. 196 (2015), pp 161–165
64  http://dx.doi.org/10.1016/j.cpc.2015.06.003
65 
66  K.Savvidy and G.Savvidy
67  Spectrum and Entropy of C-systems. MIXMAX random number generator
68  Chaos, Solitons & Fractals, Volume 91, (2016) pp. 33–38
69  http://dx.doi.org/10.1016/j.chaos.2016.05.003
70 
71  The period of the generator is 10^4682 for N=256, and
72  10^1597 for N=88
73 
74  This implementation is only a wrapper around the real implemention, see mixmax.cxx and mixmax.h
75  The generator, in C code, is available also at hepforge: http://mixmax.hepforge.org
76 
77 
78  @ingroup Random
79  */
80 
81  template<int N, int SkipNumber>
82  class MixMaxEngine : public TRandomEngine {
83 
84  public:
85 
87 
88  // this should be changed for WINDOWS
89 #ifndef __LP64__
90  typedef uint64_t StateInt_t;
91 #else
92  typedef unsigned long long StateInt_t;
93 #endif
94  typedef uint64_t Result_t;
95 
96 
97  MixMaxEngine(uint64_t seed=1);
98 
99  virtual ~MixMaxEngine();
100 
101 
102  /// Get the size of the generator
103  static int Size();
104 
105  /// maximum integer that can be generated. For MIXMAX is 2^61-1
106  static uint64_t MaxInt();
107 
108  /// minimum integer that can be generated. For MIXMAX is 0
109  static uint64_t MinInt();
110 
111  /// set the generator seed
112  void SetSeed(Result_t seed);
113 
114  // generate a random number (virtual interface)
115  virtual double Rndm() { return Rndm_impl(); }
116 
117  /// generate a double random number (faster interface)
118  inline double operator() () { return Rndm_impl(); }
119 
120  /// generate an array of random numbers
121  void RndmArray (int n, double * array);
122 
123  /// generate a 64 bit integer number
124  Result_t IntRndm();
125 
126  /// get name of the generator
127  static std::string Name();
128 
129  protected:
130  // protected functions used for tesing the generator
131 
132  /// get the state of the generator
133  void GetState(std::vector<StateInt_t> & state) const;
134 
135 
136  ///set the full initial generator state
137  void SetState(const std::vector<StateInt_t> & state);
138 
139  /// Get the counter (between 0 and Size-1)
140  int Counter() const;
141 
142 
143  private:
144 
145  /// implementation function to generate the random number
146  double Rndm_impl();
147 
148  //rng_state_t * fRngState; // mix-max generator state
149  //mixmax::mixmax_engine<N> * fRng; // mixmax internal engine class
150  MixMaxEngineImpl<N> * fRng; // mixmax internal engine class
151 
152  };
153 
157 
158  extern template class MixMaxEngine<240,0>;
159  extern template class MixMaxEngine<256,0>;
160  extern template class MixMaxEngine<256,2>;
161  extern template class MixMaxEngine<256,4>;
162  extern template class MixMaxEngine<17,0>;
163  extern template class MixMaxEngine<17,1>;
164  extern template class MixMaxEngine<17,2>;
165 
166  } // end namespace Math
167 
168 } // end namespace ROOT
169 
170 
171 #include "Math/MixMaxEngine.icc"
172 
173 #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
This namespace contains pre-defined functions to be used in conjuction with TExecutor::Map and TExecu...
Definition: StringConv.hxx:21
virtual double Rndm()
Definition: MixMaxEngine.h:115
static uint64_t MinInt()
minimum integer that can be generated. For MIXMAX is 0
TRandomEngine BaseType
Definition: MixMaxEngine.h:86
MixMaxEngine< 256, 2 > MixMaxEngine256
Definition: MixMaxEngine.h:155
MixMaxEngineImpl< N > * fRng
Definition: MixMaxEngine.h:150
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
Wrapper class for the MIXMAX Random number generator.
Definition: MixMaxEngine.h:82
int Counter() const
Get the counter (between 0 and Size-1)
double operator()()
generate a double random number (faster interface)
Definition: MixMaxEngine.h:118
static int Size()
Get the size of the generator.
MixMaxEngine< 240, 0 > MixMaxEngine240
Definition: MixMaxEngine.h:154
Result_t IntRndm()
generate a 64 bit integer number
MixMaxEngine< 17, 0 > MixMaxEngine17
Definition: MixMaxEngine.h:156
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