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 10.5 ] [ 10.5.p1 ] [ 10.6 ] [ 10.6.p1 ] [ 10.6.p2 ] [ 10.6.p3 ] [ 10.7 ] [ 10.7.p1 ] [ 10.7.p2 ] [ 10.7.p3 ] [ 10.7.p4 ] [ 11.0 ] [ 11.0.p1 ] [ 11.0.p2 ] [ 11.0.p3, ] [ 11.0.p4 ] [ 11.1 ] [ 11.1.1 ] [ 11.1.2 ] [ 11.1.3 ] [ 11.2 ] [ 11.2.1 ] [ 11.2.2 ] [ 11.3.0 ]

  1 //
  2 // -*- C++ -*-
  3 //
  4 // -----------------------------------------------------------------------
  5 //                             HEP Random
  6 //                       --- RanluxppEngine ---
  7 //                         class header file
  8 // -----------------------------------------------------------------------
  9 // Implementation of the RANLUX++ generator
 10 //
 11 // RANLUX++ is an LCG equivalent of RANLUX using 576 bit numbers.
 12 //
 13 // References:
 14 // A. Sibidanov
 15 //   A revision of the subtract-with-borrow random numbergenerators
 16 //   Computer Physics Communications, 221(2017), 299-303
 17 //
 18 // J. Hahnfeld, L. Moneta
 19 //   A Portable Implementation of RANLUX++
 20 //   vCHEP2021
 21 
 22 #ifndef RanluxppEngine_h
 23 #define RanluxppEngine_h
 24 
 25 #include "CLHEP/Random/RandomEngine.h"
 26 
 27 #include <cstdint>
 28 
 29 namespace CLHEP {
 30 
 31 /**
 32  * @author Jonas Hahnfeld
 33  * @ingroup random
 34  */
 35 class RanluxppEngine final : public HepRandomEngine {
 36 
 37 public:
 38   RanluxppEngine();
 39   RanluxppEngine(long seed);
 40   RanluxppEngine(std::istream &is);
 41   virtual ~RanluxppEngine();
 42   // Constructors and destructor
 43 
 44   double flat() override;
 45   // It returns a pseudo random number between 0 and 1,
 46   // excluding the end points.
 47 
 48   void flatArray(const int size, double *vect) override;
 49   // Fills the array "vect" of specified size with flat random values.
 50 
 51   void setSeed(long seed, int dummy = 0) override;
 52   // Sets the state of the algorithm according to seed.
 53 
 54   void setSeeds(const long *seeds, int dummy = 0) override;
 55   // Sets the state of the algorithm according to the zero terminated
 56   // array of seeds.  Only the first seed is used.
 57 
 58   void skip(uint64_t n);
 59   // Skip `n` random numbers without generating them.
 60 
 61   void saveStatus(const char filename[] = "Ranluxpp.conf") const override;
 62   // Saves in named file the current engine status.
 63 
 64   void restoreStatus(const char filename[] = "Ranluxpp.conf") override;
 65   // Reads from named file the last saved engine status and restores it.
 66 
 67   void showStatus() const override;
 68   // Dumps the engine status on the screen.
 69 
 70   std::string name() const override;
 71 
 72   // Optional methods to serialize the engine's state into vectors and streams.
 73   static std::string engineName();
 74   static std::string beginTag();
 75 
 76   std::ostream &put(std::ostream &os) const override;
 77   std::istream &get(std::istream &is) override;
 78 
 79   std::istream &getState(std::istream &is) override;
 80 
 81   std::vector<unsigned long> put() const override;
 82   bool get(const std::vector<unsigned long> &v) override;
 83   bool getState(const std::vector<unsigned long> &v) override;
 84 
 85   // Save and restore to/from streams
 86   operator double() override { return flat(); }
 87   operator float() override { return float(flat()); }
 88   operator unsigned int() override { return (unsigned int)nextRandomBits(); }
 89 
 90   // 1 value for the engine ID, 2 * 9 values for the state, and 2 more values
 91   // for the carry bit and the position.
 92   static const unsigned int VECTOR_STATE_SIZE = 21;
 93 
 94 private:
 95   void advance();
 96   uint64_t nextRandomBits();
 97 
 98   uint64_t fState[9]; ///< RANLUX state of the generator
 99   unsigned fCarry;    ///< Carry bit of the RANLUX state
100   int fPosition = 0;  ///< Current position in bits
101 
102 }; // RanluxppEngine
103 
104 } // namespace CLHEP
105 
106 #endif
107