CLHEP 2.4.6.4
C++ Class Library for High Energy Physics
Loading...
Searching...
No Matches
Hurd160Engine.h
Go to the documentation of this file.
1// $Id: Hurd160Engine.h,v 1.5 2010/06/16 17:24:53 garren Exp $
2// -*- C++ -*-
3//
4// -----------------------------------------------------------------------
5// HEP Random
6// --- Hurd160Engine ---
7// class header file
8// -----------------------------------------------------------------------
9//
10// The starting point for the Hurd Random algorithm is the paper in
11// IEEE Transactions on Computers c23, 2 Feb 1974. The algorithm is
12// essentially a series of 32 interconnected b-bit registers. The basic
13// property is that at each step, bit 1 becomes bit 0, bit 2 the new bit 1,
14// bit b the new bit b-1. This is modified so that the new bit b0 is the old
15// bit b1 XOR'd with some bit b-d from the previous bit register. The values
16// of d can be chosen so as to generate a primitive polynomial, a maximal
17// length sequence through all bit patterns except the zero pattern.
18//
19// This generator, Hurd160 use values based upon Table I of the afore
20// mentioned paper, such that we have 160 total bits, representing 32
21// 5-bit registers (actually implemented as an array of 5 32-bit words)
22// =======================================================================
23// 07-23-98 KLS Initial draft started
24// Ken Smith - Added conversion operators: 6th Aug 1998
25// Mark Fischler - Methods put, get for instance save/restore 12/8/04
26// Mark Fischler - methods for anonymous save/restore 12/27/04
27// =======================================================================
28
29#ifndef Hurd160Engine_h
30#define Hurd160Engine_h
31
32#include "CLHEP/Random/defs.h"
33#include "CLHEP/Random/RandomEngine.h"
34
35namespace CLHEP {
36
37/**
38 * @author
39 * @ingroup random
40 */
42
43public:
44
46 Hurd160Engine( std::istream &is);
47 Hurd160Engine( long seed );
48 Hurd160Engine( int rowIndex, int colIndex );
49 virtual ~Hurd160Engine();
50 // Constructors and destructor.
51
52 double flat();
53 // Returns a pseudo random number between 0 and 1
54
55 void flatArray( const int size, double* vect );
56 // Fills the array "vect" of specified size with flat random values.
57
58 void setSeed( long seed, int );
59 // Sets the state of the algorithm according to seed.
60
61 void setSeeds( const long* seeds, int );
62 // Sets the state of the algorithm according to the zero-terminated
63 // array of seeds.
64
65 void saveStatus( const char filename[] = "Hurd160Engine.conf" ) const;
66 // Saves on named file the current engine status
67
68 void restoreStatus( const char filename[] = "Hurd160Engine.conf" );
69 // Reads from named file the last saved engine status
70 // and restores it.
71
72 void showStatus() const;
73 // Dumps the engine status on the screen
74
75 operator double(); // Returns same as flat()
76 operator float(); // flat value, without worrying about filling bits
77 operator unsigned int(); // 32-bit flat value, quickest of all
78
79 virtual std::ostream & put (std::ostream & os) const;
80 virtual std::istream & get (std::istream & is);
81
82 std::string name() const;
83 static std::string engineName() {return "Hurd160Engine";}
84 static std::string beginTag ( );
85 virtual std::istream & getState ( std::istream & is );
86
87 std::vector<unsigned long> put () const;
88 bool get (const std::vector<unsigned long> & v);
89 bool getState (const std::vector<unsigned long> & v);
90
91 static const unsigned int VECTOR_STATE_SIZE = 7;
92
93private:
94
95 void advance();
96
97 long seeds_[2];
98 int wordIndex;
99 unsigned int words[5];
100
101}; // Hurd160Engine
102
103} // namespace CLHEP
104
105#ifdef ENABLE_BACKWARDS_COMPATIBILITY
106// backwards compatibility will be enabled ONLY in CLHEP 1.9
107using namespace CLHEP;
108#endif
109
110#endif // Hurd160Engine_h
static const unsigned int VECTOR_STATE_SIZE
Definition: Hurd160Engine.h:91
virtual std::istream & get(std::istream &is)
void setSeeds(const long *seeds, int)
void restoreStatus(const char filename[]="Hurd160Engine.conf")
void showStatus() const
virtual std::istream & getState(std::istream &is)
std::vector< unsigned long > put() const
static std::string engineName()
Definition: Hurd160Engine.h:83
void flatArray(const int size, double *vect)
void setSeed(long seed, int)
static std::string beginTag()
void saveStatus(const char filename[]="Hurd160Engine.conf") const
std::string name() const
#define double(obj)
Definition: excDblThrow.cc:32