Logo ROOT  
Reference Guide
 
Loading...
Searching...
No Matches
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
18namespace ROOT {
19
20 namespace Math {
21
22
24
25 template<class Generator>
27 static const char * Name() { return "std_random_eng";}
28 };
29 template<>
30 struct StdEngineType<std::minstd_rand> {
31 static const char * Name() { return "std_minstd_rand";}
32 };
33 template<>
34 struct StdEngineType<std::mt19937> {
35 static const char * Name() { return "std_mt19937";}
36 };
37 template<>
38 struct StdEngineType<std::mt19937_64> {
39 static const char * Name() { return "std_mt19937_64";}
40 };
41 template<>
42 struct StdEngineType<std::ranlux24> {
43 static const char * Name() { return "std_ranlux24";}
44 };
45 template<>
46 struct StdEngineType<std::ranlux48> {
47 static const char * Name() { return "std_ranlux48";}
48 };
49 template<>
50 struct StdEngineType<std::knuth_b> {
51 static const char * Name() { return "std_knuth_b";}
52 };
53 template<>
54 struct StdEngineType<std::random_device> {
55 static const char * Name() { return "std_random_device";}
56 };
57
58
59 /**
60 @ingroup Random
61 Class to wrap engines fron the C++ standard random library in
62 the ROOT Random interface.
63 These cases are then used by the generic TRandomGen class
64 to provide TRandom interrace generators for the C++ random generators.
65
66 See for examples the TRandomMT64 and TRandomRanlux48 generators
67 which are typede's to TRandomGen instantiated with some
68 random engine from the C++ standard library.
69
70 */
71
72 template <class Generator>
73 class StdEngine {
74
75
76 public:
77
79 typedef typename Generator::result_type Result_t;
80
82 fCONS = 1./fGen.max();
83 }
84
85
86 void SetSeed(Result_t seed) { fGen.seed(seed);}
87
88 double Rndm() {
89 Result_t rndm = fGen(); // generate integer number according to the type
90 if (rndm != 0) return fCONS*rndm;
91 return Rndm();
92 }
93
95 return fGen();
96 }
97
98 double operator() () {
99 return Rndm();
100 }
101
102 static const char * Name() {
104 }
105
106 static uint64_t MaxInt() { return Generator::max(); }
107
108
109 private:
110 Generator fGen;
111 double fCONS; //! cached value of maximum integer value generated
112 };
113
114
115 extern template class StdEngine<std::mt19937_64>;
116 extern template class StdEngine<std::ranlux48>;
117
118 } // end namespace Math
119
120} // end namespace ROOT
121
122
123#endif /* ROOT_Math_StdEngine */
Class to wrap engines fron the C++ standard random library in the ROOT Random interface.
Definition StdEngine.h:73
Generator::result_type Result_t
Definition StdEngine.h:79
StdRandomEngine BaseType
Definition StdEngine.h:78
static const char * Name()
Definition StdEngine.h:102
static uint64_t MaxInt()
Definition StdEngine.h:106
void SetSeed(Result_t seed)
Definition StdEngine.h:86
Namespace for new Math classes and functions.
This file contains a specialised ROOT message handler to test for diagnostic in unit tests.
static const char * Name()
Definition StdEngine.h:27