CLHEP/Random/Hurd288Engine.h

00001 // $Id: Hurd288Engine.h,v 1.9 2002/04/12 15:02:44 evc 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 // =======================================================================
00025 
00026 #ifndef Hurd288Engine_h
00027 #define Hurd288Engine_h
00028 
00029 #include "CLHEP/Random/RandomEngine.h"
00030 
00035 class Hurd288Engine: public HepRandomEngine {
00036  
00037 public:
00038 
00039   Hurd288Engine();
00040   Hurd288Engine( HepStd::istream &is );
00041   Hurd288Engine( long seed );
00042   Hurd288Engine( int rowIndex, int colIndex );
00043   virtual ~Hurd288Engine();
00044   // Constructors and destructor.
00045 
00046   Hurd288Engine( const Hurd288Engine &p );
00047   Hurd288Engine & operator = ( const Hurd288Engine &p );
00048   // Copy constructor and operator=.
00049 
00050   double flat();
00051   // Returns a pseudo random number between 0 and 1
00052 
00053   void flatArray( const int size, double* vect );
00054   // Fills the array "vect" of specified size with flat random values.
00055 
00056   void setSeed( long seed, int );
00057   // Sets the state of the algorithm according to seed.
00058 
00059   void setSeeds( const long* seeds, int );
00060   // Sets the state of the algorithm according to the zero-terminated
00061   // array of seeds. 
00062 
00063   void saveStatus( const char filename[] = "Hurd288Engine.conf" ) const;
00064   // Saves on named file the current engine status
00065 
00066   void restoreStatus( const char filename[] = "Hurd288Engine.conf" );
00067   // Reads from named file the last saved engine status
00068   // and restores it.
00069 
00070   void showStatus() const;
00071   // Dumps the engine status on the screen
00072 
00073   operator float();      // flat value, without worrying about filling bits
00074   operator unsigned int();  // 32-bit flat value, quickest of all
00075 
00076   friend HepStd::ostream& operator<< ( HepStd::ostream& os, const Hurd288Engine& e );
00077   friend HepStd::istream& operator>> ( HepStd::istream& is,       Hurd288Engine& e );
00078 
00079 private:
00080   static int numEngines;
00081   static int maxIndex;
00082 
00083   static double twoToMinus_32;
00084   static double twoToMinus_53;
00085   static double nearlyTwoToMinus_54;
00086   void powersOfTwo();
00087   void advance();
00088 
00089   int wordIndex;
00090   unsigned int words[9];
00091 
00092 }; // Hurd288Engine
00093 
00094 #endif // Hurd288Engine_h

Class Library for High Energy Physics (version 1.8)