Geant4 Cross Reference |
1 // -*- C++ -*- 1 2 // 3 // ------------------------------------------- 4 // HEP Random 5 // --- MTwistEngine --- 6 // class header file 7 // ------------------------------------------- 8 // A "fast, compact, huge-period generator" ba 9 // T. Nishimura, "Mersenne Twister: A 623-dime 10 // uniform pseudorandom number generator", to 11 // Modeling and Computer Simulation. It is a 12 // with a Mersenne-prime period of 2^19937-1, 13 // For further information, see http://www.mat 14 // =========================================== 15 // Ken Smith - Started initial draft: 14t 16 // - Optimized to get pow() out 17 // - Added conversion operators 18 // M Fischler - Changes in way powers of two 19 // Mark Fischler - Methods for distrib. insta 20 // Mark Fischler methods for anonymous save 21 // =========================================== 22 23 #ifndef MTwistEngine_h 24 #define MTwistEngine_h 25 26 #include "CLHEP/Random/RandomEngine.h" 27 28 namespace CLHEP { 29 30 /** 31 * @author 32 * @ingroup random 33 */ 34 class MTwistEngine : public HepRandomEngine { 35 36 public: 37 38 MTwistEngine(); 39 MTwistEngine( long seed ); 40 MTwistEngine( int rowIndex, int colIndex ); 41 MTwistEngine( std::istream & is ); 42 virtual ~MTwistEngine(); 43 // Constructors and destructor. 44 45 double flat(); 46 // Returns a pseudo random number between 0 47 48 void flatArray(const int size, double* vect) 49 // Fills an array "vect" of specified size w 50 51 void setSeed(long seed, int); 52 // Sets the state of the algorithm according 53 54 void setSeeds(const long * seeds, int); 55 // Sets the state of the algorithm according 56 // array of seeds. It is allowed to ignore o 57 58 void saveStatus( const char filename[] = "MT 59 // Saves the current engine status in the na 60 61 void restoreStatus( const char filename[] = 62 // Reads from named file the the last saved 63 64 void showStatus() const; 65 // Dumps the current engine status on the sc 66 67 operator double(); // Returns same as 68 operator float(); // returns flat, wi 69 operator unsigned int(); // 32-bit flat, qui 70 71 virtual std::ostream & put (std::ostream & o 72 virtual std::istream & get (std::istream & i 73 static std::string beginTag ( ); 74 virtual std::istream & getState ( std::istre 75 76 std::string name() const; 77 static std::string engineName() {return "MTw 78 79 std::vector<unsigned long> put () const; 80 bool get (const std::vector<unsigned long> & 81 bool getState (const std::vector<unsigned lo 82 83 static const unsigned int VECTOR_STATE_SIZE 84 85 private: 86 87 unsigned int mt[624]; 88 int count624; 89 90 enum{ NminusM = 227, M = 397, N = 624}; 91 92 }; // MTwistEngine 93 94 } // namespace CLHEP 95 96 #endif // MTwistEngine_h 97