CLHEP VERSION Reference Documentation
CLHEP Home Page CLHEP Documentation CLHEP Bug Reports |
00001 // $Id: Hurd160Engine.h,v 1.5 2010/06/16 17:24:53 garren 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 // Mark Fischler - Methods put, get for instance save/restore 12/8/04 00026 // Mark Fischler - methods for anonymous save/restore 12/27/04 00027 // ======================================================================= 00028 00029 #ifndef Hurd160Engine_h 00030 #define Hurd160Engine_h 00031 00032 #include "CLHEP/Random/defs.h" 00033 #include "CLHEP/Random/RandomEngine.h" 00034 00035 namespace CLHEP { 00036 00041 class Hurd160Engine: public HepRandomEngine { 00042 00043 public: 00044 00045 Hurd160Engine(); 00046 Hurd160Engine( std::istream &is); 00047 Hurd160Engine( long seed ); 00048 Hurd160Engine( int rowIndex, int colIndex ); 00049 virtual ~Hurd160Engine(); 00050 // Constructors and destructor. 00051 00052 double flat(); 00053 // Returns a pseudo random number between 0 and 1 00054 00055 void flatArray( const int size, double* vect ); 00056 // Fills the array "vect" of specified size with flat random values. 00057 00058 void setSeed( long seed, int ); 00059 // Sets the state of the algorithm according to seed. 00060 00061 void setSeeds( const long* seeds, int ); 00062 // Sets the state of the algorithm according to the zero-terminated 00063 // array of seeds. 00064 00065 void saveStatus( const char filename[] = "Hurd160Engine.conf" ) const; 00066 // Saves on named file the current engine status 00067 00068 void restoreStatus( const char filename[] = "Hurd160Engine.conf" ); 00069 // Reads from named file the last saved engine status 00070 // and restores it. 00071 00072 void showStatus() const; 00073 // Dumps the engine status on the screen 00074 00075 operator float(); // flat value, without worrying about filling bits 00076 operator unsigned int(); // 32-bit flat value, quickest of all 00077 00078 virtual std::ostream & put (std::ostream & os) const; 00079 virtual std::istream & get (std::istream & is); 00080 00081 std::string name() const; 00082 static std::string engineName() {return "Hurd160Engine";} 00083 static std::string beginTag ( ); 00084 virtual std::istream & getState ( std::istream & is ); 00085 00086 std::vector<unsigned long> put () const; 00087 bool get (const std::vector<unsigned long> & v); 00088 bool getState (const std::vector<unsigned long> & v); 00089 00090 static const unsigned int VECTOR_STATE_SIZE = 7; 00091 00092 private: 00093 static int numEngines; 00094 static int maxIndex; 00095 00096 void advance(); 00097 00098 int wordIndex; 00099 unsigned int words[5]; 00100 00101 }; // Hurd160Engine 00102 00103 } // namespace CLHEP 00104 00105 #ifdef ENABLE_BACKWARDS_COMPATIBILITY 00106 // backwards compatibility will be enabled ONLY in CLHEP 1.9 00107 using namespace CLHEP; 00108 #endif 00109 00110 #endif // Hurd160Engine_h