CLHEP 2.0.4.7 Reference Documentation
   
CLHEP Home Page     CLHEP Documentation     CLHEP Bug Reports

Hurd288Engine.h

Go to the documentation of this file.
00001 // $Id: Hurd288Engine.h,v 1.3.4.2 2005/04/15 16:32:52 garren Exp $
00002 // -*- C++ -*-
00003 //
00004 // -----------------------------------------------------------------------
00005 //                           HEP Random
00006 //                     --- Hurd288Engine ---
00007 //                       class header file
00008 // -----------------------------------------------------------------------
00009 // The starting point for the Hurd Random algorithm is the paper in
00010 // IEEE Transactions on Computers c23, 2 Feb 1974. The algorithm is
00011 // essentially a series of 32 interconnected b-bit registers. The basic
00012 // property is that at each step, bit 1 becomes bit 0, bit 2 the new bit 1,
00013 // bit b the new bit b-1. This is modified so that the new bit b0 is the old
00014 // bit b1 XOR'd with some bit b-d from the previous bit register. The values
00015 // of d can be chosen so as to generate a primitive polynomial, a maximal
00016 // length sequence through all bit patterns except the zero pattern.
00017 //
00018 // This generator, Hurd288, use values based upon Table I of the afore-
00019 // mentioned paper, such that we have 288 total bits, representing 32
00020 // 9-bit registers (actually implemented as an array of 9 32-bit words)
00021 // =======================================================================
00022 //  07-23-98  KLS   Initial draft started
00023 // Ken Smith      - Added conversion operators:  6th Aug 1998
00024 // Mark Fischler  - methods for distrib. instacne save/restore 12/8/04    
00025 // Mark Fischler  - methods for anonymous save/restore 12/27/04    
00026 // =======================================================================
00027 
00028 #ifndef Hurd288Engine_h
00029 #define Hurd288Engine_h
00030 
00031 #include "CLHEP/Random/defs.h"
00032 #include "CLHEP/Random/RandomEngine.h"
00033 
00034 namespace CLHEP {
00035 
00040 class Hurd288Engine: public HepRandomEngine {
00041  
00042 public:
00043 
00044   Hurd288Engine();
00045   Hurd288Engine( std::istream &is );
00046   Hurd288Engine( long seed );
00047   Hurd288Engine( int rowIndex, int colIndex );
00048   virtual ~Hurd288Engine();
00049   // Constructors and destructor.
00050 
00051   Hurd288Engine( const Hurd288Engine &p );
00052   Hurd288Engine & operator = ( const Hurd288Engine &p );
00053   // Copy constructor and operator=.
00054 
00055   double flat();
00056   // Returns a pseudo random number between 0 and 1
00057 
00058   void flatArray( const int size, double* vect );
00059   // Fills the array "vect" of specified size with flat random values.
00060 
00061   void setSeed( long seed, int );
00062   // Sets the state of the algorithm according to seed.
00063 
00064   void setSeeds( const long* seeds, int );
00065   // Sets the state of the algorithm according to the zero-terminated
00066   // array of seeds. 
00067 
00068   void saveStatus( const char filename[] = "Hurd288Engine.conf" ) const;
00069   // Saves on named file the current engine status
00070 
00071   void restoreStatus( const char filename[] = "Hurd288Engine.conf" );
00072   // Reads from named file the last saved engine status
00073   // and restores it.
00074 
00075   void showStatus() const;
00076   // Dumps the engine status on the screen
00077 
00078   operator float();      // flat value, without worrying about filling bits
00079   operator unsigned int();  // 32-bit flat value, quickest of all
00080 
00081   virtual std::ostream & put (std::ostream & os) const;
00082   virtual std::istream & get (std::istream & is);
00083   static  std::string beginTag ( );
00084   virtual std::istream & getState ( std::istream & is );
00085 
00086   std::string name() const;
00087   static std::string engineName() {return "Hurd288Engine";}
00088 
00089   std::vector<unsigned long> put () const;
00090   bool get (const std::vector<unsigned long> & v);
00091   bool getState (const std::vector<unsigned long> & v);
00092 
00093   static const unsigned int VECTOR_STATE_SIZE = 11;
00094   
00095 private:
00096   static int numEngines;
00097   static int maxIndex;
00098 
00099   static double twoToMinus_32;
00100   static double twoToMinus_53;
00101   static double nearlyTwoToMinus_54;
00102   void powersOfTwo();
00103   void advance();
00104 
00105   int wordIndex;
00106   unsigned int words[9];
00107 
00108 }; // Hurd288Engine
00109 
00110 }  // namespace CLHEP
00111 
00112 #ifdef ENABLE_BACKWARDS_COMPATIBILITY
00113 //  backwards compatibility will be enabled ONLY in CLHEP 1.9
00114 using namespace CLHEP;
00115 #endif
00116 
00117 #endif // Hurd288Engine_h

Generated on Thu Jul 1 22:02:30 2010 for CLHEP by  doxygen 1.4.7