Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-18 10:10:21

0001 // @(#)root/mathcore:$Id$
0002 // Author: Jonas Hahnfeld 11/2020
0003 
0004 /*************************************************************************
0005  * Copyright (C) 1995-2021, Rene Brun and Fons Rademakers.               *
0006  * All rights reserved.                                                  *
0007  *                                                                       *
0008  * For the licensing terms see $ROOTSYS/LICENSE.                         *
0009  * For the list of contributors see $ROOTSYS/README/CREDITS.             *
0010  *************************************************************************/
0011 
0012 #ifndef ROOT_Math_RanluxppEngine
0013 #define ROOT_Math_RanluxppEngine
0014 
0015 #include "Math/TRandomEngine.h"
0016 
0017 #include <cstdint>
0018 #include <memory>
0019 
0020 namespace ROOT {
0021 namespace Math {
0022 
0023 template <int w, int p, int u = 0>
0024 class RanluxppEngineImpl;
0025 
0026 template <int p>
0027 class RanluxppEngine final : public TRandomEngine {
0028 
0029 private:
0030    using ImplType = RanluxppEngineImpl<48, p>;
0031    std::unique_ptr<ImplType> fImpl;
0032 
0033 public:
0034    RanluxppEngine(uint64_t seed = 314159265);
0035    ~RanluxppEngine() override;
0036 
0037    /// Generate a double-precision random number with 48 bits of randomness
0038    double Rndm() override;
0039    /// Generate a double-precision random number (non-virtual method)
0040    double operator()();
0041    /// Generate a random integer value with 48 bits
0042    uint64_t IntRndm();
0043 
0044    /// Initialize and seed the state of the generator
0045    void SetSeed(uint64_t seed);
0046    /// Skip `n` random numbers without generating them
0047    void Skip(uint64_t n);
0048 
0049    /// Get name of the generator
0050    static const char *Name() { return "RANLUX++"; }
0051 };
0052 
0053 using RanluxppEngine24 = RanluxppEngine<24>;
0054 using RanluxppEngine2048 = RanluxppEngine<2048>;
0055 
0056 extern template class RanluxppEngine<24>;
0057 extern template class RanluxppEngine<2048>;
0058 
0059 
0060 template <int p>
0061 class RanluxppCompatEngineJames final : public TRandomEngine {
0062 
0063 private:
0064    using ImplType = RanluxppEngineImpl<24, p>;
0065    std::unique_ptr<ImplType> fImpl;
0066 
0067 public:
0068    RanluxppCompatEngineJames(uint64_t seed = 314159265);
0069    ~RanluxppCompatEngineJames() override;
0070 
0071    /// Generate a floating point random number with 24 bits of randomness
0072    double Rndm() override;
0073    /// Generate a floating point random number (non-virtual method)
0074    double operator()();
0075    /// Generate a random integer value with 24 bits
0076    uint64_t IntRndm();
0077 
0078    /// Initialize and seed the state of the generator
0079    void SetSeed(uint64_t seed);
0080    /// Skip `n` random numbers without generating them
0081    void Skip(uint64_t n);
0082 
0083    /// Get name of the generator
0084    static const char *Name() { return "RanluxppCompatJames"; }
0085 };
0086 
0087 /// Compatibility engine for original RANLUX implementation by James, luxury
0088 /// level 3 (p = 223). The sequence of numbers also matches `gsl_rng_ranlux`.
0089 using RanluxppCompatEngineJamesP3 = RanluxppCompatEngineJames<223>;
0090 /// Compatibility engine for original RANLUX implementation by James, luxury
0091 /// level 4 (p = 389). The sequence of numbers also matches `gsl_rng_ranlux389`.
0092 using RanluxppCompatEngineJamesP4 = RanluxppCompatEngineJames<389>;
0093 
0094 extern template class RanluxppCompatEngineJames<223>;
0095 extern template class RanluxppCompatEngineJames<389>;
0096 
0097 
0098 /// Compatibility engine for `gsl_rng_ranlxs*` from the GNU Scientific Library.
0099 template <int p>
0100 class RanluxppCompatEngineGslRanlxs final : public TRandomEngine {
0101 
0102 private:
0103    using ImplType = RanluxppEngineImpl<24, p>;
0104    std::unique_ptr<ImplType> fImpl;
0105 
0106 public:
0107    RanluxppCompatEngineGslRanlxs(uint64_t seed = 1);
0108    ~RanluxppCompatEngineGslRanlxs() override;
0109 
0110    /// Generate a floating point random number with 24 bits of randomness
0111    double Rndm() override;
0112    /// Generate a floating point random number (non-virtual method)
0113    double operator()();
0114    /// Generate a random integer value with 24 bits
0115    uint64_t IntRndm();
0116 
0117    /// Initialize and seed the state of the generator
0118    void SetSeed(uint64_t seed);
0119    /// Skip `n` random numbers without generating them
0120    void Skip(uint64_t n);
0121 
0122    /// Get name of the generator
0123    static const char *Name() { return "RanluxppCompatGslRanlxs"; }
0124 };
0125 
0126 using RanluxppCompatEngineGslRanlxs0 = RanluxppCompatEngineGslRanlxs<218>;
0127 using RanluxppCompatEngineGslRanlxs1 = RanluxppCompatEngineGslRanlxs<404>;
0128 using RanluxppCompatEngineGslRanlxs2 = RanluxppCompatEngineGslRanlxs<794>;
0129 
0130 extern template class RanluxppCompatEngineGslRanlxs<218>;
0131 extern template class RanluxppCompatEngineGslRanlxs<404>;
0132 extern template class RanluxppCompatEngineGslRanlxs<794>;
0133 
0134 
0135 /// Compatibility engine for `gsl_rng_ranlxd*` from the GNU Scientific Library.
0136 template <int p>
0137 class RanluxppCompatEngineGslRanlxd final : public TRandomEngine {
0138 
0139 private:
0140    using ImplType = RanluxppEngineImpl<48, p>;
0141    std::unique_ptr<ImplType> fImpl;
0142 
0143 public:
0144    RanluxppCompatEngineGslRanlxd(uint64_t seed = 1);
0145    ~RanluxppCompatEngineGslRanlxd() override;
0146 
0147    /// Generate a floating point random number with 48 bits of randomness
0148    double Rndm() override;
0149    /// Generate a floating point random number (non-virtual method)
0150    double operator()();
0151    /// Generate a random integer value with 48 bits
0152    uint64_t IntRndm();
0153 
0154    /// Initialize and seed the state of the generator
0155    void SetSeed(uint64_t seed);
0156    /// Skip `n` random numbers without generating them
0157    void Skip(uint64_t n);
0158 
0159    /// Get name of the generator
0160    static const char *Name() { return "RanluxppCompatGslRanlxd"; }
0161 };
0162 
0163 using RanluxppCompatEngineGslRanlxd1 = RanluxppCompatEngineGslRanlxd<404>;
0164 using RanluxppCompatEngineGslRanlxd2 = RanluxppCompatEngineGslRanlxd<794>;
0165 
0166 extern template class RanluxppCompatEngineGslRanlxd<404>;
0167 extern template class RanluxppCompatEngineGslRanlxd<794>;
0168 
0169 
0170 template <int w, int p>
0171 class RanluxppCompatEngineLuescherImpl;
0172 
0173 /// Compatibility engine for Lüscher's ranlxs implementation written in C.
0174 template <int p>
0175 class RanluxppCompatEngineLuescherRanlxs final : public TRandomEngine {
0176 
0177 private:
0178    using ImplType = RanluxppCompatEngineLuescherImpl<24, p>;
0179    std::unique_ptr<ImplType> fImpl;
0180 
0181 public:
0182    RanluxppCompatEngineLuescherRanlxs(uint64_t seed = 314159265);
0183    ~RanluxppCompatEngineLuescherRanlxs() override;
0184 
0185    /// Generate a floating point random number with 24 bits of randomness
0186    double Rndm() override;
0187    /// Generate a floating point random number (non-virtual method)
0188    double operator()();
0189    /// Generate a random integer value with 24 bits
0190    uint64_t IntRndm();
0191 
0192    /// Initialize and seed the state of the generator
0193    void SetSeed(uint64_t seed);
0194    /// Skip `n` random numbers without generating them
0195    void Skip(uint64_t n);
0196 
0197    /// Get name of the generator
0198    static const char *Name() { return "RanluxppCompatLuescherRanlxs"; }
0199 };
0200 
0201 using RanluxppCompatEngineLuescherRanlxs0 = RanluxppCompatEngineLuescherRanlxs<218>;
0202 using RanluxppCompatEngineLuescherRanlxs1 = RanluxppCompatEngineLuescherRanlxs<404>;
0203 using RanluxppCompatEngineLuescherRanlxs2 = RanluxppCompatEngineLuescherRanlxs<794>;
0204 
0205 extern template class RanluxppCompatEngineLuescherRanlxs<218>;
0206 extern template class RanluxppCompatEngineLuescherRanlxs<404>;
0207 extern template class RanluxppCompatEngineLuescherRanlxs<794>;
0208 
0209 
0210 /// Compatibility engine for Lüscher's ranlxd implementation written in C.
0211 template <int p>
0212 class RanluxppCompatEngineLuescherRanlxd final : public TRandomEngine {
0213 
0214 private:
0215    using ImplType = RanluxppCompatEngineLuescherImpl<48, p>;
0216    std::unique_ptr<ImplType> fImpl;
0217 
0218 public:
0219    RanluxppCompatEngineLuescherRanlxd(uint64_t seed = 314159265);
0220    ~RanluxppCompatEngineLuescherRanlxd() override;
0221 
0222    /// Generate a floating point random number with 48 bits of randomness
0223    double Rndm() override;
0224    /// Generate a floating point random number (non-virtual method)
0225    double operator()();
0226    /// Generate a random integer value with 48 bits
0227    uint64_t IntRndm();
0228 
0229    /// Initialize and seed the state of the generator
0230    void SetSeed(uint64_t seed);
0231    /// Skip `n` random numbers without generating them
0232    void Skip(uint64_t n);
0233 
0234    /// Get name of the generator
0235    static const char *Name() { return "RanluxppCompatLuescherRanlxd"; }
0236 };
0237 using RanluxppCompatEngineLuescherRanlxd1 = RanluxppCompatEngineLuescherRanlxd<404>;
0238 using RanluxppCompatEngineLuescherRanlxd2 = RanluxppCompatEngineLuescherRanlxd<794>;
0239 
0240 extern template class RanluxppCompatEngineLuescherRanlxd<404>;
0241 extern template class RanluxppCompatEngineLuescherRanlxd<794>;
0242 
0243 
0244 /// Compatibility engine for `std::ranlux24` from the C++ standard.
0245 class RanluxppCompatEngineStdRanlux24 final : public TRandomEngine {
0246 
0247 private:
0248    using ImplType = RanluxppEngineImpl<24, 223, 23>;
0249    std::unique_ptr<ImplType> fImpl;
0250 
0251 public:
0252    RanluxppCompatEngineStdRanlux24(uint64_t seed = 19780503);
0253    ~RanluxppCompatEngineStdRanlux24() override;
0254 
0255    /// Generate a floating point random number with 24 bits of randomness
0256    double Rndm() override;
0257    /// Generate a floating point random number (non-virtual method)
0258    double operator()();
0259    /// Generate a random integer value with 24 bits
0260    uint64_t IntRndm();
0261 
0262    /// Initialize and seed the state of the generator
0263    void SetSeed(uint64_t seed);
0264    /// Skip `n` random numbers without generating them
0265    void Skip(uint64_t n);
0266 
0267    /// Get name of the generator
0268    static const char *Name() { return "RanluxppCompatStdRanlux24"; }
0269 };
0270 
0271 
0272 /// Compatibility engine for `std::ranlux48` from the C++ standard.
0273 class RanluxppCompatEngineStdRanlux48 final : public TRandomEngine {
0274 
0275 private:
0276    using ImplType = RanluxppEngineImpl<48, 2 * 389, 11>;
0277    std::unique_ptr<ImplType> fImpl;
0278 
0279 public:
0280    RanluxppCompatEngineStdRanlux48(uint64_t seed = 19780503);
0281    ~RanluxppCompatEngineStdRanlux48() override;
0282 
0283    /// Generate a floating point random number with 48 bits of randomness
0284    double Rndm() override;
0285    /// Generate a floating point random number (non-virtual method)
0286    double operator()();
0287    /// Generate a random integer value with 48 bits
0288    uint64_t IntRndm();
0289 
0290    /// Initialize and seed the state of the generator
0291    void SetSeed(uint64_t seed);
0292    /// Skip `n` random numbers without generating them
0293    void Skip(uint64_t n);
0294 
0295    /// Get name of the generator
0296    static const char *Name() { return "RanluxppCompatStdRanlux48"; }
0297 };
0298 
0299 } // end namespace Math
0300 } // end namespace ROOT
0301 
0302 #endif /* ROOT_Math_RanluxppEngine */