00001 // $Id: Hurd160Engine.h,v 1.9 2002/04/12 15:02:44 evc Exp $ 00002 // -*- C++ -*- 00003 // 00004 // ----------------------------------------------------------------------- 00005 // HEP Random 00006 // --- Hurd160Engine --- 00007 // class header file 00008 // ----------------------------------------------------------------------- 00009 // 00010 // The starting point for the Hurd Random algorithm is the paper in 00011 // IEEE Transactions on Computers c23, 2 Feb 1974. The algorithm is 00012 // essentially a series of 32 interconnected b-bit registers. The basic 00013 // property is that at each step, bit 1 becomes bit 0, bit 2 the new bit 1, 00014 // bit b the new bit b-1. This is modified so that the new bit b0 is the old 00015 // bit b1 XOR'd with some bit b-d from the previous bit register. The values 00016 // of d can be chosen so as to generate a primitive polynomial, a maximal 00017 // length sequence through all bit patterns except the zero pattern. 00018 // 00019 // This generator, Hurd160 use values based upon Table I of the afore 00020 // mentioned paper, such that we have 160 total bits, representing 32 00021 // 5-bit registers (actually implemented as an array of 5 32-bit words) 00022 // ======================================================================= 00023 // 07-23-98 KLS Initial draft started 00024 // Ken Smith - Added conversion operators: 6th Aug 1998 00025 // ======================================================================= 00026 00027 #ifndef Hurd160Engine_h 00028 #define Hurd160Engine_h 00029 00030 #include "CLHEP/Random/RandomEngine.h" 00031 00036 class Hurd160Engine: public HepRandomEngine { 00037 00038 public: 00039 00040 Hurd160Engine(); 00041 Hurd160Engine( HepStd::istream &is); 00042 Hurd160Engine( long seed ); 00043 Hurd160Engine( int rowIndex, int colIndex ); 00044 virtual ~Hurd160Engine(); 00045 // Constructors and destructor. 00046 00047 Hurd160Engine( const Hurd160Engine &p ); 00048 Hurd160Engine & operator = ( const Hurd160Engine &p ); 00049 // Copy constructor and operator=. 00050 00051 double flat(); 00052 // Returns a pseudo random number between 0 and 1 00053 00054 void flatArray( const int size, double* vect ); 00055 // Fills the array "vect" of specified size with flat random values. 00056 00057 void setSeed( long seed, int ); 00058 // Sets the state of the algorithm according to seed. 00059 00060 void setSeeds( const long* seeds, int ); 00061 // Sets the state of the algorithm according to the zero-terminated 00062 // array of seeds. 00063 00064 void saveStatus( const char filename[] = "Hurd160Engine.conf" ) const; 00065 // Saves on named file the current engine status 00066 00067 void restoreStatus( const char filename[] = "Hurd160Engine.conf" ); 00068 // Reads from named file the last saved engine status 00069 // and restores it. 00070 00071 void showStatus() const; 00072 // Dumps the engine status on the screen 00073 00074 operator float(); // flat value, without worrying about filling bits 00075 operator unsigned int(); // 32-bit flat value, quickest of all 00076 00077 friend HepStd::ostream& operator<< ( HepStd::ostream& os, const Hurd160Engine& e ); 00078 friend HepStd::istream& operator>> ( HepStd::istream& is, Hurd160Engine& e ); 00079 00080 private: 00081 static int numEngines; 00082 static int maxIndex; 00083 00084 static double twoToMinus_32; 00085 static double twoToMinus_53; 00086 static double nearlyTwoToMinus_54; 00087 void powersOfTwo(); 00088 void advance(); 00089 00090 int wordIndex; 00091 unsigned int words[5]; 00092 00093 }; // Hurd160Engine 00094 00095 #endif // Hurd160Engine_h