CLHEP 2.0.4.7 Reference Documentation
CLHEP Home Page CLHEP Documentation CLHEP Bug Reports |
00001 // $Id: RandEngine.h,v 1.3.4.3 2005/04/15 16:32:52 garren 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 // M Fischler - Inserted warnings about the fact that the quality of rand() 00029 // is quite poor. 00030 // Mark Fischler Methods for distrib. instance save/restore 12/8/04 00031 // Mark Fischler methods for anonymous save/restore 12/27/04 00032 // ======================================================================= 00033 00034 #ifndef RandEngine_h 00035 #define RandEngine_h 1 00036 00037 #include "CLHEP/Random/defs.h" 00038 #include "CLHEP/Random/RandomEngine.h" 00039 00040 namespace CLHEP { 00041 00046 class RandEngine : public HepRandomEngine { 00047 00048 public: 00049 00050 RandEngine(std::istream& is); 00051 RandEngine(); 00052 RandEngine(long seed); 00053 RandEngine(int rowIndex, int colIndex); 00054 virtual ~RandEngine(); 00055 // Constructors and destructor 00056 00057 double flat(); 00058 // It returns a pseudo random number between 0 and 1, 00059 // according to the standard stdlib random function rand() 00060 // but excluding the end points. 00061 // 00062 // WARNING: rand() is quite a weak generator on most systems, < 00063 // will not pass several randomness tests, and does not give a < 00064 // reproducible sequence of numbers. < 00065 00066 void flatArray (const int size, double* vect); 00067 // Fills the array "vect" of specified size with flat random values. 00068 00069 void setSeed(long seed, int dum=0); 00070 // Sets the state of the algorithm according to seed. 00071 00072 void setSeeds(const long * seeds, int dum=0); 00073 // Sets the state of the algorithm according to the zero terminated 00074 // array of seeds. Only the first seed is used. 00075 00076 void saveStatus( const char filename[] = "Rand.conf" ) const; 00077 // Saves on file Rand.conf the current engine status. 00078 // WARNING: This is non-functional, as rand() on various systems will < 00079 // not give reproducible streams. < 00080 00081 void restoreStatus( const char filename[] = "Rand.conf" ); 00082 // Reads from file Rand.conf the last saved engine status 00083 // and restores it. 00084 // WARNING: This is non-functional, as rand() on various systems will < 00085 // not give reproducible streams. < 00086 00087 void showStatus() const; 00088 // Dumps the engine status on the screen. 00089 00090 operator unsigned int(); // 32-bit flat value, quickest of all. 00091 00092 virtual std::ostream & put (std::ostream & os) const; 00093 virtual std::istream & get (std::istream & is); 00094 static std::string beginTag ( ); 00095 virtual std::istream & getState ( std::istream & is ); 00096 00097 std::string name() const; 00098 static std::string engineName() {return "RandEngine";} 00099 00100 std::vector<unsigned long> put () const; 00101 bool get (const std::vector<unsigned long> & v); 00102 bool getState (const std::vector<unsigned long> & v); 00103 00104 static const unsigned int VECTOR_STATE_SIZE = 3; 00105 00106 private: 00107 00108 RandEngine(const RandEngine &p); 00109 RandEngine & operator = (const RandEngine &p); 00110 // Private copy constructor and assignment operator. 00111 00112 private: 00113 00114 const double mantissa_bit_32; 00115 long seq; 00116 static int numEngines; 00117 static int maxIndex; 00118 00119 }; 00120 00121 } // namespace CLHEP 00122 00123 #ifdef ENABLE_BACKWARDS_COMPATIBILITY 00124 // backwards compatibility will be enabled ONLY in CLHEP 1.9 00125 using namespace CLHEP; 00126 #endif 00127 00128 #endif