ROOT  6.06/09
Reference Guide
TRandomEngine.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_TRandomEngine
14 #define ROOT_Math_TRandomEngine
15 
16 
17 
18 namespace ROOT {
19 
20  namespace Math {
21 
23  public:
24  virtual double Rndm() = 0;
25  virtual ~RandomBaseEngine() {}
26  };
27 
28 
30  public:
31  virtual ~TRandomEngine() {}
32  };
33 
34  class LCGEngine : public TRandomEngine {
35 
36 
37  public:
38 
40 
41  LCGEngine() : fSeed(65539) { }
42 
43  virtual ~LCGEngine() {}
44 
45  void SetSeed(unsigned int seed) { fSeed = seed; }
46 
47  virtual double Rndm() {
48  //double Rndm() {
49  return Rndm_impl();
50  }
51  double Rndm_impl() {
52  const double kCONS = 4.6566128730774E-10; // (1/pow(2,31)
53  unsigned int rndm = IntRndm(); // generate integer number
54  if (rndm != 0) return kCONS*rndm;
55  return Rndm_impl();
56  }
57  inline double operator() () { return Rndm_impl(); }
58 
59  unsigned int IntRndm() {
60  fSeed = (1103515245 * fSeed + 12345) & 0x7fffffffUL;
61  return fSeed;
62  }
63 
64  private:
65  unsigned int fSeed;
66  };
67 
68 
69  } // end namespace Math
70 
71 } // end namespace ROOT
72 
73 
74 #endif /* ROOT_Math_TRandomEngine */
unsigned int IntRndm()
Definition: TRandomEngine.h:59
Namespace for new ROOT classes and functions.
Definition: ROOT.py:1
virtual double Rndm()
Definition: TRandomEngine.h:47
void SetSeed(unsigned int seed)
Definition: TRandomEngine.h:45
TRandomEngine BaseType
Definition: TRandomEngine.h:39
Namespace for new Math classes and functions.
virtual double Rndm()=0