Geant4 Cross Reference |
1 // -*- C++ -*- 1 2 // 3 // ------------------------------------------- 4 // Hep Random 5 // --- DualRand --- 6 // class header file 7 // ------------------------------------------- 8 // 9 // Canopy random number generator DualRand 10 // Re-written as C++ routine for 32-bit ints 11 // 12 // Exclusive or of a feedback shift register 13 // random number generator. The feedback shi 14 // 127 and 97. The integer congruence genera 15 // multiplier for each stream. The multiplie 16 // full period and maximum "potency" for modu 17 // the combined random number generator is 2^ 18 // sequences are different for each stream (n 19 // different place). 20 // 21 // =========================================== 22 // Canopy random number generator DualRand. 23 // Doug Toussaint 5/25/88 24 // Optimized by GMH 7/26/88 25 // Optimized by GMH 7/26/88 26 // Repaired by GMH 12/1/88 to update modular 27 // Put into ranlib by GMH 6/23/89 28 // Re-written as C++ routine for 32-bit ints 29 // Re-written for CLHEP package KLS 6/0 30 // Removed pow() from flat method for speed K 31 // Ken Smith - Added conversion operators: 32 // Mark Fischler methods for distrib. inst 33 // Mark Fischler methods for anonymous sav 34 // Mark Fischler - methods for vector save/re 35 // =========================================== 36 37 38 #ifndef DualRand_h 39 #define DualRand_h 40 41 #include "CLHEP/Random/RandomEngine.h" 42 43 namespace CLHEP { 44 45 /** 46 * @author 47 * @ingroup random 48 */ 49 class DualRand: public HepRandomEngine { 50 51 public: 52 53 DualRand(); 54 DualRand(long seed); 55 DualRand(std::istream & is); 56 DualRand(int rowIndex, int colIndex); 57 virtual ~DualRand(); 58 59 // let the compiler generate the copy constr 60 //DualRand(const DualRand & p); 61 //DualRand & operator=(const DualRand & p); 62 63 double flat(); 64 // Returns a pseudo random number between 0 65 // (excluding the end points) 66 67 void flatArray(const int size, double * vect 68 // Fills an array "vect" of specified size w 69 70 void setSeed(long seed, int); 71 // Sets the state of the algorithm according 72 73 void setSeeds(const long * seeds, int); 74 // Sets the state of the algorithm according 75 // array of seeds. 76 77 void saveStatus( const char filename[] = "Du 78 // Saves on named file the current engine st 79 80 void restoreStatus( const char filename[] = 81 // Reads from named file the last saved engi 82 83 void showStatus() const; 84 // Dumps the current engine status on the sc 85 86 operator double(); // Returns same as 87 operator float(); // flat value, wit 88 operator unsigned int(); // 32-bit flat val 89 90 virtual std::ostream & put (std::ostream & o 91 virtual std::istream & get (std::istream & i 92 static std::string beginTag ( ); 93 virtual std::istream & getState ( std::istre 94 95 std::string name() const; 96 static std::string engineName() {return "Dua 97 98 std::vector<unsigned long> put () const; 99 bool get (const std::vector<unsigned long> & 100 bool getState (const std::vector<unsigned lo 101 102 static const unsigned int VECTOR_STATE_SIZE 103 104 private: 105 106 // This generator is composed of two others 107 108 class Tausworthe { 109 public: 110 Tausworthe(); 111 Tausworthe(unsigned int seed); 112 operator unsigned int(); 113 void put(std::ostream & os) const; 114 void put(std::vector<unsigned long> & v) c 115 void get(std::istream & is); 116 bool get(std::vector<unsigned long>::const 117 private: 118 int wordIndex; 119 unsigned int words[4]; 120 }; // Tausworthe 121 122 class IntegerCong { 123 public: 124 IntegerCong(); 125 IntegerCong(unsigned int seed, int streamN 126 operator unsigned int(); 127 void put(std::ostream & os) const; 128 void put(std::vector<unsigned long> & v) c 129 void get(std::istream & is); 130 bool get(std::vector<unsigned long>::const 131 private: 132 unsigned int state, multiplier, addend; 133 }; // IntegerCong 134 135 int numEngines; 136 Tausworthe tausworthe; 137 IntegerCong integerCong; 138 139 }; // DualRand 140 141 } // namespace CLHEP 142 143 #endif // DualRand_h 144