Logo ROOT   6.10/09
Reference Guide
StdEngine.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_StdEngine
14 #define ROOT_Math_StdEngine
15 
16 #include <random>
17 #include <string>
18 
19 namespace ROOT {
20 
21  namespace Math {
22 
23 
24  class StdRandomEngine {};
25 
26  template<class Generator>
27  struct StdEngineType {
28  static std::string Name() { return "std_random_eng";}
29  };
30  template<>
31  struct StdEngineType<std::minstd_rand> {
32  static std::string Name() { return "std_minstd_rand";}
33  };
34  template<>
35  struct StdEngineType<std::mt19937> {
36  static std::string Name() { return "std_mt19937";}
37  };
38  template<>
39  struct StdEngineType<std::mt19937_64> {
40  static std::string Name() { return "std_mt19937_64";}
41  };
42  template<>
43  struct StdEngineType<std::ranlux24> {
44  static std::string Name() { return "std_ranlux24";}
45  };
46  template<>
47  struct StdEngineType<std::ranlux48> {
48  static std::string Name() { return "std_ranlux48";}
49  };
50  template<>
51  struct StdEngineType<std::knuth_b> {
52  static std::string Name() { return "std_knuth_b";}
53  };
54  template<>
55  struct StdEngineType<std::random_device> {
56  static std::string Name() { return "std_random_device";}
57  };
58 
59 
60  /**
61  Wrapper class for std::random generator to be included in ROOT
62  */
63 
64  template <class Generator>
65  class StdEngine {
66 
67 
68  public:
69 
71  typedef typename Generator::result_type Result_t;
72 
73  StdEngine() : fGen() {
74  fCONS = 1./fGen.max();
75  }
76 
77 
78  void SetSeed(Result_t seed) { fGen.seed(seed);}
79 
80  double Rndm() {
81  Result_t rndm = fGen(); // generate integer number according to the type
82  if (rndm != 0) return fCONS*rndm;
83  return Rndm();
84  }
85 
86  Result_t IntRndm() {
87  return fGen();
88  }
89 
90  double operator() () {
91  return Rndm();
92  }
93 
94  static std::string Name() {
96  }
97 
98  static uint64_t MaxInt() { return Generator::max(); }
99 
100 
101  private:
102  Generator fGen;
103  double fCONS; //! cached value of maximum integer value generated
104  };
105 
106 
107  extern template class StdEngine<std::mt19937_64>;
108  extern template class StdEngine<std::ranlux48>;
109 
110  } // end namespace Math
111 
112 } // end namespace ROOT
113 
114 
115 #endif /* ROOT_Math_StdEngine */
Namespace for new ROOT classes and functions.
Definition: StringConv.hxx:21
StdRandomEngine BaseType
Definition: StdEngine.h:70
static uint64_t MaxInt()
Definition: StdEngine.h:98
STL namespace.
TRObject operator()(const T1 &t1) const
static std::string Name()
Definition: StdEngine.h:94
static std::string Name()
Definition: StdEngine.h:28
Result_t IntRndm()
Definition: StdEngine.h:86
Wrapper class for std::random generator to be included in ROOT.
Definition: StdEngine.h:65
Namespace for new Math classes and functions.
void SetSeed(Result_t seed)
Definition: StdEngine.h:78
Generator::result_type Result_t
Definition: StdEngine.h:71