ROOT  6.06/09
Reference Guide
MersenneTwisterEngine.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_MersenneTwisterEngine
14 #define ROOT_Math_MersenneTwisterEngine
15 
16 #ifndef ROOT_Math_TRandomEngine
17 #include "Math/TRandomEngine.h"
18 #endif
19 
20 #include <stdint.h>
21 
22 namespace ROOT {
23 
24  namespace Math {
25 
26  /**
27  Random number generator class based on
28  M. Matsumoto and T. Nishimura,
29  Mersenne Twister: A 623-diminsionally equidistributed
30  uniform pseudorandom number generator
31  ACM Transactions on Modeling and Computer Simulation,
32  Vol. 8, No. 1, January 1998, pp 3--30.
33 
34  For more information see the Mersenne Twister homepage
35  [http://www.math.keio.ac.jp/~matumoto/emt.html]
36 
37  Advantage:
38 
39  - large period 2**19937 -1
40  - relativly fast (slightly slower than TRandom1 and TRandom2 but much faster than TRandom1)
41 
42  Drawback: a relative large internal state of 624 integers
43 
44  @ingroup Random
45  */
46 
48 
49 
50  public:
51 
53 
54  MersenneTwisterEngine(unsigned int seed=4357) {
55  SetSeed(seed);
56  }
57 
59 
60  void SetSeed(unsigned int seed);
61 
62 
63  virtual double Rndm() {
64  return Rndm_impl();
65  }
66  inline double operator() () { return Rndm_impl(); }
67 
68  unsigned int IntRndm() {
69  // fSeed = (1103515245 * fSeed + 12345) & 0x7fffffffUL;
70  // return fSeed;
71  return (int) Rndm_impl(); // t.b. impl
72  }
73 
74  private:
75 
76  double Rndm_impl();
77 
78 
79  uint32_t fMt[624];
80  int fCount624;
81  };
82 
83 
84  } // end namespace Math
85 
86 } // end namespace ROOT
87 
88 
89 #endif /* ROOT_Math_TRandomEngines */
Namespace for new ROOT classes and functions.
Definition: ROOT.py:1
Random number generator class based on M.
double Rndm_impl()
generate a random double number
void SetSeed(unsigned int seed)
set the seed x
MersenneTwisterEngine(unsigned int seed=4357)
Namespace for new Math classes and functions.