ROOT  6.06/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 
19 #ifndef ROOT_Math_TRandomEngine
20 #include "Math/TRandomEngine.h"
21 #endif
22 
23 
24 struct rng_state_st; /// forward declare generator state
25 
26 typedef struct rng_state_st rng_state_t;
27 
28 
29 namespace ROOT {
30 
31  namespace Math {
32 
33 
34  /**
35  MIXMAX Random number generator.
36  It is a matrix-recursive random number generator introduced by
37  G. Savvidy in N.Z.Akopov, G.K.Savvidy and N.G.Ter-Arutyunian, _Matrix Generator of Pseudorandom Numbers_,
38  J.Comput.Phys. 97, 573 (1991) [DOI Link](http://dx.doi.org/10.1016/0021-9991(91)90016-E).
39  This is a new very fast impelmentation by K. Savvidy
40  by K. Savvidy and described in this paper,
41  K. Savvidy, _The MIXMAX Random Number Generator_, Comp. Phys. Communic. (2015)
42  [DOI link](http://dx.doi.org/10.1016/j.cpc.2015.06.003)
43 
44  The period of the generator is 10^4682 for N=256, and
45  10^1597 for N=88
46 
47  This implementation is only a wrapper around the real implemention, see mixmax.cxx and mixmax.h
48  The generator, in C code, is available also at hepforge: http://mixmax.hepforge.org
49 
50 
51  @ingroup Random
52  */
53 
54 
55  class MixMaxEngine : public TRandomEngine {
56 
57 
58  public:
59 
61 
62  // this should be changed for WINDOWS
63  typedef unsigned long long int StateInt_t;
64 
65 
66 
67  MixMaxEngine(uint64_t seed=1);
68 
69  virtual ~MixMaxEngine();
70 
71  /// get the state of the generator
72  void GetState(std::vector<StateInt_t> & state) const;
73 
74  /// Get the counter (between 0 and Size-1)
75  int Counter() const;
76 
77  /// Get the size of the generator
78  static int Size();
79 
80  /// maximum integer that can be generated. For MIXMAX is 2^61-1
81  static uint64_t MaxInt() { return 0x1fffffffffffffff; } // 2^61 -1
82 
83  /// set the generator seed
84  void SetSeed(unsigned int seed);
85 
86  /// set the generator seed using a 64 bits integer
87  void SetSeed64(uint64_t seed);
88 
89  ///set the full initial generator state and warm up generator by doing some iterations
90  void SetState(const std::vector<StateInt_t> & state, bool warmup = true);
91 
92  /// set the counter
93  void SetCounter(int val);
94 
95  // /// set the special number
96 
97  // static void SetSpecialNumber(uint64_t val);
98 
99  // generate a random number (virtual interface)
100  virtual double Rndm() { return Rndm_impl(); }
101 
102  /// generate a double random number (faster interface)
103  inline double operator() () { return Rndm_impl(); }
104 
105  /// generate an array of random numbers
106  void RndmArray (int n, double * array);
107 
108  /// generate a 64 bit integer number
109  uint64_t IntRndm();
110 
111  /// set the number we want to use to skip generation
112  /// higher value means higher luxury but slower
113  static void SetSkipNumber(int nskip);
114 
115  /// set initial number to be used in the vector.
116  /// The previous elements are skipped and not returned.
117  static void SetFirstReturnElement(int index);
118 
119 
120  private:
121 
122  /// implementation function to generrate the random number
123  double Rndm_impl();
124 
125  rng_state_t * fRngState; // mix-max generator state
126 
127  };
128 
129 
130  } // end namespace Math
131 
132 } // end namespace ROOT
133 
134 
135 #endif /* ROOT_Math_TRandomEngines */
static void SetSkipNumber(int nskip)
set the number we want to use to skip generation higher value means higher luxury but slower ...
Namespace for new ROOT classes and functions.
Definition: ROOT.py:1
unsigned long long int StateInt_t
Definition: MixMaxEngine.h:63
static void SetFirstReturnElement(int index)
set initial number to be used in the vector.
double operator()()
generate a double random number (faster interface)
Definition: MixMaxEngine.h:103
TRandomEngine BaseType
Definition: MixMaxEngine.h:60
void SetState(const std::vector< StateInt_t > &state, bool warmup=true)
set the full initial generator state and warm up generator by doing some iterations ...
virtual double Rndm()
Definition: MixMaxEngine.h:100
void SetSeed64(uint64_t seed)
set the generator seed using a 64 bits integer
void SetSeed(unsigned int seed)
set the generator seed
MIXMAX Random number generator.
Definition: MixMaxEngine.h:55
void GetState(std::vector< StateInt_t > &state) const
get the state of the generator
void RndmArray(int n, double *array)
generate an array of random numbers
int nskip
Definition: mixmax.cxx:39
uint64_t IntRndm()
generate a 64 bit integer number
Namespace for new Math classes and functions.
static uint64_t MaxInt()
maximum integer that can be generated. For MIXMAX is 2^61-1
Definition: MixMaxEngine.h:81
int Counter() const
Get the counter (between 0 and Size-1)
void SetCounter(int val)
set the counter
double Rndm_impl()
implementation function to generrate the random number
MixMaxEngine(uint64_t seed=1)
static int Size()
Get the size of the generator.
const Int_t n
Definition: legend1.C:16