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