CLHEP VERSION Reference Documentation
CLHEP Home Page CLHEP Documentation CLHEP Bug Reports |
00001 // $Id: DualRand.h,v 1.5 2010/06/16 17:24:53 garren Exp $ 00002 // -*- C++ -*- 00003 // 00004 // ----------------------------------------------------------------------- 00005 // Hep Random 00006 // --- DualRand --- 00007 // class header file 00008 // ----------------------------------------------------------------------- 00009 // 00010 // Canopy random number generator DualRand 00011 // Re-written as C++ routine for 32-bit ints MF 1/26/98 00012 // 00013 // Exclusive or of a feedback shift register and integer congruence 00014 // random number generator. The feedback shift register uses offsets 00015 // 127 and 97. The integer congruence generator uses a different 00016 // multiplier for each stream. The multipliers are chosen to give 00017 // full period and maximum "potency" for modulo 2^32. The period of 00018 // the combined random number generator is 2^159 - 2^32, and the 00019 // sequences are different for each stream (not just started in a 00020 // different place). 00021 // 00022 // ======================================================================= 00023 // Canopy random number generator DualRand. 00024 // Doug Toussaint 5/25/88 00025 // Optimized by GMH 7/26/88 00026 // Optimized by GMH 7/26/88 00027 // Repaired by GMH 12/1/88 to update modular congruence state 00028 // Put into ranlib by GMH 6/23/89 00029 // Re-written as C++ routine for 32-bit ints MF 1/26/98 00030 // Re-written for CLHEP package KLS 6/04/98 00031 // Removed pow() from flat method for speed KLS 7/21/98 00032 // Ken Smith - Added conversion operators: 6th Aug 1998 00033 // Mark Fischler methods for distrib. instance save/restore 12/8/04 00034 // Mark Fischler methods for anonymous save/restore 12/27/04 00035 // Mark Fischler - methods for vector save/restore 3/7/05 00036 // ======================================================================= 00037 00038 00039 #ifndef DualRand_h 00040 #define DualRand_h 00041 00042 #include "CLHEP/Random/defs.h" 00043 #include "CLHEP/Random/RandomEngine.h" 00044 00045 namespace CLHEP { 00046 00051 class DualRand: public HepRandomEngine { 00052 00053 public: 00054 00055 DualRand(); 00056 DualRand(long seed); 00057 DualRand(std::istream & is); 00058 DualRand(int rowIndex, int colIndex); 00059 virtual ~DualRand(); 00060 00061 // let the compiler generate the copy constructors 00062 //DualRand(const DualRand & p); 00063 //DualRand & operator=(const DualRand & p); 00064 00065 double flat(); 00066 // Returns a pseudo random number between 0 and 1 00067 // (excluding the end points) 00068 00069 void flatArray(const int size, double * vect); 00070 // Fills an array "vect" of specified size with flat random values. 00071 00072 void setSeed(long seed, int); 00073 // Sets the state of the algorithm according to seed. 00074 00075 void setSeeds(const long * seeds, int); 00076 // Sets the state of the algorithm according to the zero-terminated 00077 // array of seeds. 00078 00079 void saveStatus( const char filename[] = "DualRand.conf") const; 00080 // Saves on named file the current engine status. 00081 00082 void restoreStatus( const char filename[] = "DualRand.conf" ); 00083 // Reads from named file the last saved engine status and restores it. 00084 00085 void showStatus() const; 00086 // Dumps the current engine status on the screen. 00087 00088 operator float(); // flat value, without worrying about filling bits 00089 operator unsigned int(); // 32-bit flat value, quickest of all 00090 00091 virtual std::ostream & put (std::ostream & os) const; 00092 virtual std::istream & get (std::istream & is); 00093 static std::string beginTag ( ); 00094 virtual std::istream & getState ( std::istream & is ); 00095 00096 std::string name() const; 00097 static std::string engineName() {return "DualRand";} 00098 00099 std::vector<unsigned long> put () const; 00100 bool get (const std::vector<unsigned long> & v); 00101 bool getState (const std::vector<unsigned long> & v); 00102 00103 static const unsigned int VECTOR_STATE_SIZE = 9; 00104 00105 private: 00106 00107 static int numEngines; 00108 00109 // This generator is composed of two others combined: 00110 00111 class Tausworthe { 00112 public: 00113 Tausworthe(); 00114 Tausworthe(unsigned int seed); 00115 operator unsigned int(); 00116 void put(std::ostream & os) const; 00117 void put(std::vector<unsigned long> & v) const; 00118 void get(std::istream & is); 00119 bool get(std::vector<unsigned long>::const_iterator & iv); 00120 private: 00121 int wordIndex; 00122 unsigned int words[4]; 00123 }; // Tausworthe 00124 00125 class IntegerCong { 00126 public: 00127 IntegerCong(); 00128 IntegerCong(unsigned int seed, int streamNumber); 00129 operator unsigned int(); 00130 void put(std::ostream & os) const; 00131 void put(std::vector<unsigned long> & v) const; 00132 void get(std::istream & is); 00133 bool get(std::vector<unsigned long>::const_iterator & iv); 00134 private: 00135 unsigned int state, multiplier, addend; 00136 }; // IntegerCong 00137 00138 Tausworthe tausworthe; 00139 IntegerCong integerCong; 00140 00141 }; // DualRand 00142 00143 } // namespace CLHEP 00144 00145 #ifdef ENABLE_BACKWARDS_COMPATIBILITY 00146 // backwards compatibility will be enabled ONLY in CLHEP 1.9 00147 using namespace CLHEP; 00148 #endif 00149 00150 #endif // DualRand_h