Geant4 11.1.1
Toolkit for the simulation of the passage of particles through matter
Loading...
Searching...
No Matches
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
27#include <cstdint>
28
29namespace CLHEP {
30
31/**
32 * @author Jonas Hahnfeld
33 * @ingroup random
34 */
35class RanluxppEngine final : public HepRandomEngine {
36
37public:
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
94private:
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
void showStatus() const override
void saveStatus(const char filename[]="Ranluxpp.conf") const override
std::string name() const override
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