00001 // $Id: JamesRandom.h,v 1.16 2002/04/12 15:02:44 evc Exp $ 00002 // -*- C++ -*- 00003 // 00004 // ----------------------------------------------------------------------- 00005 // HEP Random 00006 // --- HepJamesRandom --- 00007 // class header file 00008 // ----------------------------------------------------------------------- 00009 // This file is part of Geant4 (simulation toolkit for HEP). 00010 // 00011 // HepJamesRandom implements the algorithm by Marsaglia-Zaman RANMAR 00012 // described in "F.James, Comp. Phys. Comm. 60 (1990) 329" and implemented 00013 // in FORTRAN77 as part of the MATHLIB HEP library for pseudo-random 00014 // numbers generation. 00015 // This is the default random engine invoked by each distribution unless 00016 // the user sets a different one. 00017 00018 // ======================================================================= 00019 // Gabriele Cosmo - Created: 5th September 1995 00020 // - Minor corrections: 31st October 1996 00021 // - Added methods for engine status: 19th November 1996 00022 // - setSeed(), setSeeds() now have default dummy argument 00023 // set to zero: 11th July 1997 00024 // J.Marraffino - Added stream operators and related constructor. 00025 // Added automatic seed selection from seed table and 00026 // engine counter: 16th Feb 1998 00027 // Ken Smith - Added conversion operators: 6th Aug 1998 00028 // V. Innocente - changed pointers to indices 3 may 2000 00029 // ======================================================================= 00030 00031 #ifndef HepJamesRandom_h 00032 #define HepJamesRandom_h 1 00033 00034 #include "CLHEP/Random/RandomEngine.h" 00035 00040 class HepJamesRandom: public HepRandomEngine { 00041 00042 public: 00043 00044 HepJamesRandom(HepStd::istream& is); 00045 HepJamesRandom(); 00046 HepJamesRandom(long seed); 00047 HepJamesRandom(int rowIndex, int colIndex); 00048 virtual ~HepJamesRandom(); 00049 // Constructor and destructor. 00050 00051 HepJamesRandom(const HepJamesRandom &p); 00052 // Copy constructor 00053 00054 HepJamesRandom & operator = (const HepJamesRandom &p); 00055 // Overloaded assignment operator, to retrieve the engine status. 00056 00057 double flat(); 00058 // Returns a pseudo random number between 0 and 1 00059 // (excluding the end points) 00060 00061 void flatArray (const int size, double* vect); 00062 // Fills the array "vect" of specified size with flat random values. 00063 00064 void setSeed(long seed, int dum=0); 00065 // Sets the state of the algorithm according to seed. 00066 00067 void setSeeds(const long * seeds, int dum=0); 00068 // Sets the state of the algorithm according to the zero terminated 00069 // array of seeds. Only the first seed is used. 00070 00071 void saveStatus( const char filename[] = "JamesRand.conf" ) const; 00072 // Saves on file JamesRand.conf the current engine status. 00073 00074 void restoreStatus( const char filename[] = "JamesRand.conf" ); 00075 // Reads from file JamesRand.conf the last saved engine status 00076 // and restores it. 00077 00078 void showStatus() const; 00079 // Dumps the engine status on the screen. 00080 00081 operator unsigned int(); 00082 // 32-bit flat, but slower than double or float. 00083 00084 friend HepStd::ostream& operator<< (HepStd::ostream& os, const HepJamesRandom& e); 00085 friend HepStd::istream& operator>> (HepStd::istream& is, HepJamesRandom& e); 00086 00087 private: 00088 00089 // Members defining the current status of the generator. 00090 double u[97]; 00091 double c, cd, cm; 00092 int i97, j97; 00093 static int numEngines; 00094 static int maxIndex; 00095 }; 00096 00097 #endif