File indexing completed on 2025-01-18 10:10:18
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013 #ifndef ROOT_Math_LCGEngine
0014 #define ROOT_Math_LCGEngine
0015
0016 #include <cassert>
0017 #include <cstdint>
0018 #include <string>
0019 #include <vector>
0020
0021 class TRandomEngine {
0022 public:
0023 virtual double Rndm() = 0;
0024 virtual ~TRandomEngine() {}
0025 };
0026
0027
0028 namespace ROOT {
0029
0030 namespace Math {
0031
0032
0033 class LCGEngine : public TRandomEngine {
0034
0035
0036 public:
0037
0038 typedef TRandomEngine BaseType;
0039 typedef uint32_t Result_t;
0040 typedef uint32_t StateInt_t;
0041
0042 LCGEngine() : fSeed(65539) { }
0043
0044 ~LCGEngine() override {}
0045
0046 void SetSeed(uint32_t seed) { fSeed = seed; }
0047
0048 double Rndm() override {
0049
0050 return Rndm_impl();
0051 }
0052 inline double operator() () { return Rndm_impl(); }
0053
0054 uint32_t IntRndm() {
0055 fSeed = (1103515245 * fSeed + 12345) & 0x7fffffffUL;
0056 return fSeed;
0057 }
0058
0059
0060 static unsigned int MinInt() { return 0; }
0061
0062 static unsigned int MaxInt() { return 0xffffffff; }
0063
0064 static int Size() { return 1; }
0065
0066 static std::string Name() { return "LCGEngine"; }
0067 protected:
0068
0069 void SetState(const std::vector<uint32_t> & state) {
0070 assert(!state.empty());
0071 fSeed = state[0];
0072 }
0073
0074 void GetState(std::vector<uint32_t> & state) {
0075 state.resize(1);
0076 state[0] = fSeed;
0077 }
0078 int Counter() const { return 0; }
0079 private:
0080
0081 double Rndm_impl() {
0082 const double kCONS = 4.6566128730774E-10;
0083 unsigned int rndm = IntRndm();
0084 if (rndm != 0) return kCONS*rndm;
0085 return Rndm_impl();
0086 }
0087
0088 uint32_t fSeed;
0089 };
0090
0091
0092 }
0093
0094 }
0095
0096
0097 #endif