CLHEP 2.0.4.7 Reference Documentation
CLHEP Home Page CLHEP Documentation CLHEP Bug Reports |
00001 // $Id: Hurd160Engine.h,v 1.3.4.2 2005/04/15 16:32:52 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 Hurd160Engine( const Hurd160Engine &p ); 00053 Hurd160Engine & operator = ( const Hurd160Engine &p ); 00054 // Copy constructor and operator=. 00055 00056 double flat(); 00057 // Returns a pseudo random number between 0 and 1 00058 00059 void flatArray( const int size, double* vect ); 00060 // Fills the array "vect" of specified size with flat random values. 00061 00062 void setSeed( long seed, int ); 00063 // Sets the state of the algorithm according to seed. 00064 00065 void setSeeds( const long* seeds, int ); 00066 // Sets the state of the algorithm according to the zero-terminated 00067 // array of seeds. 00068 00069 void saveStatus( const char filename[] = "Hurd160Engine.conf" ) const; 00070 // Saves on named file the current engine status 00071 00072 void restoreStatus( const char filename[] = "Hurd160Engine.conf" ); 00073 // Reads from named file the last saved engine status 00074 // and restores it. 00075 00076 void showStatus() const; 00077 // Dumps the engine status on the screen 00078 00079 operator float(); // flat value, without worrying about filling bits 00080 operator unsigned int(); // 32-bit flat value, quickest of all 00081 00082 virtual std::ostream & put (std::ostream & os) const; 00083 virtual std::istream & get (std::istream & is); 00084 00085 std::string name() const; 00086 static std::string engineName() {return "Hurd160Engine";} 00087 static std::string beginTag ( ); 00088 virtual std::istream & getState ( std::istream & is ); 00089 00090 std::vector<unsigned long> put () const; 00091 bool get (const std::vector<unsigned long> & v); 00092 bool getState (const std::vector<unsigned long> & v); 00093 00094 static const unsigned int VECTOR_STATE_SIZE = 7; 00095 00096 private: 00097 static int numEngines; 00098 static int maxIndex; 00099 00100 static double twoToMinus_32; 00101 static double twoToMinus_53; 00102 static double nearlyTwoToMinus_54; 00103 void powersOfTwo(); 00104 void advance(); 00105 00106 int wordIndex; 00107 unsigned int words[5]; 00108 00109 }; // Hurd160Engine 00110 00111 } // namespace CLHEP 00112 00113 #ifdef ENABLE_BACKWARDS_COMPATIBILITY 00114 // backwards compatibility will be enabled ONLY in CLHEP 1.9 00115 using namespace CLHEP; 00116 #endif 00117 00118 #endif // Hurd160Engine_h