Geant4-11
RanluxppEngine.h
Go to the documentation of this file.
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
26
27namespace CLHEP {
28
33class RanluxppEngine final : public HepRandomEngine {
34
35public:
37 RanluxppEngine(long seed);
38 RanluxppEngine(std::istream &is);
39 virtual ~RanluxppEngine();
40 // Constructors and destructor
41
42 double flat() override;
43 // It returns a pseudo random number between 0 and 1,
44 // excluding the end points.
45
46 void flatArray(const int size, double *vect) override;
47 // Fills the array "vect" of specified size with flat random values.
48
49 void setSeed(long seed, int dummy = 0) override;
50 // Sets the state of the algorithm according to seed.
51
52 void setSeeds(const long *seeds, int dummy = 0) override;
53 // Sets the state of the algorithm according to the zero terminated
54 // array of seeds. Only the first seed is used.
55
56 void skip(uint64_t n);
57 // Skip `n` random numbers without generating them.
58
59 void saveStatus(const char filename[] = "Ranluxpp.conf") const override;
60 // Saves in named file the current engine status.
61
62 void restoreStatus(const char filename[] = "Ranluxpp.conf") override;
63 // Reads from named file the last saved engine status and restores it.
64
65 void showStatus() const override;
66 // Dumps the engine status on the screen.
67
68 std::string name() const override;
69
70 // Optional methods to serialize the engine's state into vectors and streams.
71 static std::string engineName();
72 static std::string beginTag();
73
74 std::ostream &put(std::ostream &os) const override;
75 std::istream &get(std::istream &is) override;
76
77 std::istream &getState(std::istream &is) override;
78
79 std::vector<unsigned long> put() const override;
80 bool get(const std::vector<unsigned long> &v) override;
81 bool getState(const std::vector<unsigned long> &v) override;
82
83 // Save and restore to/from streams
84 operator double() override { return flat(); }
85 operator float() override { return float(flat()); }
86 operator unsigned int() override { return (unsigned int)nextRandomBits(); }
87
88 // 1 value for the engine ID, 2 * 9 values for the state, and 2 more values
89 // for the carry bit and the position.
90 static const unsigned int VECTOR_STATE_SIZE = 21;
91
92private:
93 void advance();
94 uint64_t nextRandomBits();
95
96 uint64_t fState[9];
97 unsigned fCarry;
98 int fPosition = 0;
99
100}; // RanluxppEngine
101
102} // namespace CLHEP
103
104#endif
void showStatus() const override
unsigned fCarry
Carry bit of the RANLUX state.
void saveStatus(const char filename[]="Ranluxpp.conf") const override
std::string name() const override
uint64_t fState[9]
RANLUX state of the generator.
int fPosition
Current position in bits.
void skip(uint64_t n)
std::istream & get(std::istream &is) override
static std::string engineName()
double flat() override
std::vector< unsigned long > put() const override
void setSeeds(const long *seeds, int dummy=0) override
void restoreStatus(const char filename[]="Ranluxpp.conf") override
static const unsigned int VECTOR_STATE_SIZE
void flatArray(const int size, double *vect) override
void setSeed(long seed, int dummy=0) override
std::istream & getState(std::istream &is) override
static std::string beginTag()
Definition: DoubConv.h:17