File indexing completed on 2025-01-30 10:22:09
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013 #ifndef ROOT_Math_StdEngine
0014 #define ROOT_Math_StdEngine
0015
0016 #include <random>
0017
0018 namespace ROOT {
0019
0020 namespace Math {
0021
0022
0023 class StdRandomEngine {};
0024
0025 template<class Generator>
0026 struct StdEngineType {
0027 static const char * Name() { return "std_random_eng";}
0028 };
0029 template<>
0030 struct StdEngineType<std::minstd_rand> {
0031 static const char * Name() { return "std_minstd_rand";}
0032 };
0033 template<>
0034 struct StdEngineType<std::mt19937> {
0035 static const char * Name() { return "std_mt19937";}
0036 };
0037 template<>
0038 struct StdEngineType<std::mt19937_64> {
0039 static const char * Name() { return "std_mt19937_64";}
0040 };
0041 template<>
0042 struct StdEngineType<std::ranlux24> {
0043 static const char * Name() { return "std_ranlux24";}
0044 };
0045 template<>
0046 struct StdEngineType<std::ranlux48> {
0047 static const char * Name() { return "std_ranlux48";}
0048 };
0049 template<>
0050 struct StdEngineType<std::knuth_b> {
0051 static const char * Name() { return "std_knuth_b";}
0052 };
0053 template<>
0054 struct StdEngineType<std::random_device> {
0055 static const char * Name() { return "std_random_device";}
0056 };
0057
0058
0059
0060
0061
0062
0063
0064
0065
0066
0067
0068
0069
0070
0071
0072 template <class Generator>
0073 class StdEngine {
0074
0075
0076 public:
0077
0078 typedef StdRandomEngine BaseType;
0079 typedef typename Generator::result_type Result_t;
0080
0081 StdEngine() : fGen() {
0082 fCONS = 1./fGen.max();
0083 }
0084
0085
0086 void SetSeed(Result_t seed) { fGen.seed(seed);}
0087
0088 double Rndm() {
0089 Result_t rndm = fGen();
0090 if (rndm != 0) return fCONS*rndm;
0091 return Rndm();
0092 }
0093
0094 Result_t IntRndm() {
0095 return fGen();
0096 }
0097
0098 double operator() () {
0099 return Rndm();
0100 }
0101
0102 static const char * Name() {
0103 return StdEngineType<Generator>::Name();
0104 }
0105
0106 static uint64_t MaxInt() { return Generator::max(); }
0107
0108
0109 private:
0110 Generator fGen;
0111 double fCONS;
0112 };
0113
0114
0115 extern template class StdEngine<std::mt19937_64>;
0116 extern template class StdEngine<std::ranlux48>;
0117
0118 }
0119
0120 }
0121
0122
0123 #endif