00001 // $Id: RandEngine.h,v 1.12 2002/04/12 15:02:44 evc Exp $ 00002 // -*- C++ -*- 00003 // 00004 // ----------------------------------------------------------------------- 00005 // HEP Random 00006 // --- RandEngine --- 00007 // class header file 00008 // ----------------------------------------------------------------------- 00009 // This file is part of Geant4 (simulation toolkit for HEP). 00010 // 00011 // Simple random engine using rand() and srand() functions from C standard 00012 // library to implement the flat() basic distribution and for setting 00013 // seeds. 00014 // Copy constructor and operator= are private for objects of this class. 00015 00016 // ======================================================================= 00017 // Gabriele Cosmo - Created: 5th September 1995 00018 // - Minor corrections: 31st October 1996 00019 // - Added methods for engine status: 19th November 1996 00020 // - setSeed(), setSeeds() now have default dummy argument 00021 // set to zero: 11th July 1997 00022 // - Private copy constructor and operator=: 26th Feb 1998 00023 // J.Marraffino - Added stream operators and related constructor. 00024 // Added automatic seed selection from seed table and 00025 // engine counter: 15th Feb 1998 00026 // Ken Smith - Added conversion operators: 6th Aug 1998 00027 // replace mx by mantissa_bit_32 00028 // ======================================================================= 00029 00030 #ifndef RandEngine_h 00031 #define RandEngine_h 1 00032 00033 #include "CLHEP/Random/RandomEngine.h" 00034 00039 class RandEngine : public HepRandomEngine { 00040 00041 public: 00042 00043 RandEngine(HepStd::istream& is); 00044 RandEngine(); 00045 RandEngine(long seed); 00046 RandEngine(int rowIndex, int colIndex); 00047 virtual ~RandEngine(); 00048 // Constructors and destructor 00049 00050 double flat(); 00051 // It returns a pseudo random number between 0 and 1, 00052 // according to the standard stdlib random function rand() 00053 // but excluding the end points. 00054 00055 void flatArray (const int size, double* vect); 00056 // Fills the array "vect" of specified size with flat random values. 00057 00058 void setSeed(long seed, int dum=0); 00059 // Sets the state of the algorithm according to seed. 00060 00061 void setSeeds(const long * seeds, int dum=0); 00062 // Sets the state of the algorithm according to the zero terminated 00063 // array of seeds. Only the first seed is used. 00064 00065 void saveStatus( const char filename[] = "Rand.conf" ) const; 00066 // Saves on file Rand.conf the current engine status. 00067 00068 void restoreStatus( const char filename[] = "Rand.conf" ); 00069 // Reads from file Rand.conf the last saved engine status 00070 // and restores it. 00071 00072 void showStatus() const; 00073 // Dumps the engine status on the screen. 00074 00075 operator unsigned int(); // 32-bit flat value, quickest of all. 00076 00077 friend HepStd::ostream& operator<< (HepStd::ostream& os, const RandEngine& e); 00078 friend HepStd::istream& operator>> (HepStd::istream& is, RandEngine& e); 00079 00080 private: 00081 00082 RandEngine(const RandEngine &p); 00083 RandEngine & operator = (const RandEngine &p); 00084 // Private copy constructor and assignment operator. 00085 00086 private: 00087 00088 const double mantissa_bit_32; 00089 long seq; 00090 static int numEngines; 00091 static int maxIndex; 00092 00093 }; 00094 00095 #endif