CLHEP VERSION 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.5 2010/06/16 17:24:53 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   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[] = "Hurd288Engine.conf" ) const;
00065   // Saves on named file the current engine status
00066 
00067   void restoreStatus( const char filename[] = "Hurd288Engine.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   virtual std::ostream & put (std::ostream & os) const;
00078   virtual std::istream & get (std::istream & is);
00079   static  std::string beginTag ( );
00080   virtual std::istream & getState ( std::istream & is );
00081 
00082   std::string name() const;
00083   static std::string engineName() {return "Hurd288Engine";}
00084 
00085   std::vector<unsigned long> put () const;
00086   bool get (const std::vector<unsigned long> & v);
00087   bool getState (const std::vector<unsigned long> & v);
00088 
00089   static const unsigned int VECTOR_STATE_SIZE = 11;
00090   
00091 private:
00092   static int numEngines;
00093   static int maxIndex;
00094 
00095   void advance();
00096 
00097   int wordIndex;
00098   unsigned int words[9];
00099 
00100 }; // Hurd288Engine
00101 
00102 }  // namespace CLHEP
00103 
00104 #ifdef ENABLE_BACKWARDS_COMPATIBILITY
00105 //  backwards compatibility will be enabled ONLY in CLHEP 1.9
00106 using namespace CLHEP;
00107 #endif
00108 
00109 #endif // Hurd288Engine_h

Generated on 15 Nov 2012 for CLHEP by  doxygen 1.4.7