Geant4-11
RanshiEngine.h
Go to the documentation of this file.
1// -*- C++ -*-
2//
3// -----------------------------------------------------------------------
4// HEP Random
5// --- RanshiEngine ---
6// class header file
7// -----------------------------------------------------------------------
8//
9//
10// The algorithm for this random engine was taken from "F.Gutbrod, Comp.
11// Phys. Comm. 87 (1995) 291-306".
12//
13// The algorithm can be imagined as a physical system as follows: Imagine
14// 512 "black balls" each with their own unique spin, and positions char-
15// acterized by disrete angles, where the spin is a 32-bit unsigned integer.
16// A "red ball" collides based upon the angle determined by the last 8 bits
17// of its spin, and the spin of the colliding ball is taken as the output
18// random number. The spin of the colliding ball is replaced then with the
19// left circular shift of the black ball's spin XOR'd with the red ball's
20// spin. The black ball's old spin becomes the red ball's.
21//
22// To avoid the traps presented, two measures are taken: first, the red
23// ball will oscillate between hitting the lower half of the buffer on one
24// turn and the upper half on another; second, the red ball's spin is
25// incremented by a counter of the number of random numbers produced.
26//
27// The result is scaled to a double precision floating point number to which
28// is added another random double further scaled 2^(53-32) places to the
29// right in order to ensure that the remaining bits of the result are not
30// left empty due to the mere 32 bits representation used internally.
31
32// =======================================================================
33// Ken Smith - Created: 9th June 1998
34// - Removed pow() from flat method: 21st Jul 1998
35// - Added conversion operators: 6th Aug 1998
36// Mark Fischler Methods put, get for instance save/restore 12/8/04
37// Mark Fischler methods for anonymous save/restore 12/27/04
38// =======================================================================
39
40#ifndef HepRanshiEngine_h
41#define HepRanshiEngine_h
42
44
45namespace CLHEP {
46
52
53public:
54
56 RanshiEngine(std::istream &is);
57 RanshiEngine(long seed);
58 RanshiEngine(int rowIndex, int colIndex);
59 virtual ~RanshiEngine();
60 // Constructors and destructor
61
62 double flat();
63 // Returns a pseudo random number between 0 and 1
64
65 void flatArray(const int size, double* vect);
66 // Fills the array "vect" of specified size with flat random values
67
68 void setSeed(long seed, int);
69 // Sets the state of the algorithm according to seed.
70
71 void setSeeds(const long* seeds, int);
72 // Sets the state of the algorithm according to the zero-terminated
73 // array of seeds.
74
75 void saveStatus(const char filename[] = "RanshiEngine.conf") const;
76 // Saves on named file the current engine status
77
78 void restoreStatus(const char filename[] = "RanshiEngine.conf");
79 // Reads from named file the last saved engine status
80 // and restores it.
81
82 void showStatus() const;
83 // Dumps the engine status on the screen
84
85 operator double(); // Returns same as flat()
86 operator float(); // flat value, without worrying about filling bits
87 operator unsigned int(); // 32-bit flat value, quickest of all
88
89 virtual std::ostream & put (std::ostream & os) const;
90 virtual std::istream & get (std::istream & is);
91 static std::string beginTag ( );
92 virtual std::istream & getState ( std::istream & is );
93
94 std::string name() const;
95 static std::string engineName() {return "RanshiEngine";}
96
97 std::vector<unsigned long> put () const;
98 bool get (const std::vector<unsigned long> & v);
99 bool getState (const std::vector<unsigned long> & v);
100
101private:
102 enum {numBuff = 512};
103
104 unsigned int halfBuff, numFlats;
105 unsigned int buffer[numBuff];
106 unsigned int redSpin;
107
108 static const unsigned int VECTOR_STATE_SIZE = numBuff + 4;
109
110}; // RanshiEngine
111
112} // namespace CLHEP
113
114#endif // HepRanshiEngine_h
unsigned int redSpin
Definition: RanshiEngine.h:106
unsigned int buffer[numBuff]
Definition: RanshiEngine.h:105
std::string name() const
Definition: RanshiEngine.cc:63
virtual std::istream & getState(std::istream &is)
static std::string beginTag()
void flatArray(const int size, double *vect)
virtual std::istream & get(std::istream &is)
void saveStatus(const char filename[]="RanshiEngine.conf") const
std::vector< unsigned long > put() const
static std::string engineName()
Definition: RanshiEngine.h:95
void restoreStatus(const char filename[]="RanshiEngine.conf")
void setSeeds(const long *seeds, int)
static const unsigned int VECTOR_STATE_SIZE
Definition: RanshiEngine.h:108
void setSeed(long seed, int)
void showStatus() const
unsigned int numFlats
Definition: RanshiEngine.h:104
unsigned int halfBuff
Definition: RanshiEngine.h:104
Definition: DoubConv.h:17