Geant4 11.1.1
Toolkit for the simulation of the passage of particles through matter
Loading...
Searching...
No Matches
MTwistEngine.h
Go to the documentation of this file.
1// -*- C++ -*-
2//
3// -----------------------------------------------------------------------
4// HEP Random
5// --- MTwistEngine ---
6// class header file
7// -----------------------------------------------------------------------
8// A "fast, compact, huge-period generator" based on M. Matsumoto and
9// T. Nishimura, "Mersenne Twister: A 623-dimensionally equidistributed
10// uniform pseudorandom number generator", to appear in ACM Trans. on
11// Modeling and Computer Simulation. It is a twisted GFSR generator
12// with a Mersenne-prime period of 2^19937-1, uniform on open interval (0,1)
13// For further information, see http://www.math.keio.ac.jp/~matumoto/emt.html
14// =======================================================================
15// Ken Smith - Started initial draft: 14th Jul 1998
16// - Optimized to get pow() out of flat() method: 21st Jul
17// - Added conversion operators: 6th Aug 1998
18// M Fischler - Changes in way powers of two are kept: 16-Sep-1998
19// Mark Fischler - Methods for distrib. instance save/restore 12/8/04
20// Mark Fischler methods for anonymous save/restore 12/27/04
21// =======================================================================
22
23#ifndef MTwistEngine_h
24#define MTwistEngine_h
25
27
28namespace CLHEP {
29
30/**
31 * @author
32 * @ingroup random
33 */
35
36public:
37
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 and 1 (excluding the end points).
47
48 void flatArray(const int size, double* vect);
49 // Fills an array "vect" of specified size with flat random values.
50
51 void setSeed(long seed, int);
52 // Sets the state of the algorithm according to seed.
53
54 void setSeeds(const long * seeds, int);
55 // Sets the state of the algorithm according to the zero terminated
56 // array of seeds. It is allowed to ignore one or many seeds in this array.
57
58 void saveStatus( const char filename[] = "MTwist.conf") const;
59 // Saves the current engine status in the named file
60
61 void restoreStatus( const char filename[] = "MTwist.conf" );
62 // Reads from named file the the last saved engine status and restores it.
63
64 void showStatus() const;
65 // Dumps the current engine status on the screen.
66
67 operator double(); // Returns same as flat()
68 operator float(); // returns flat, without worrying about filling bits
69 operator unsigned int(); // 32-bit flat, quickest of all
70
71 virtual std::ostream & put (std::ostream & os) const;
72 virtual std::istream & get (std::istream & is);
73 static std::string beginTag ( );
74 virtual std::istream & getState ( std::istream & is );
75
76 std::string name() const;
77 static std::string engineName() {return "MTwistEngine";}
78
79 std::vector<unsigned long> put () const;
80 bool get (const std::vector<unsigned long> & v);
81 bool getState (const std::vector<unsigned long> & v);
82
83 static const unsigned int VECTOR_STATE_SIZE = 626;
84
85private:
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
virtual std::istream & get(std::istream &is)
virtual std::istream & getState(std::istream &is)
void flatArray(const int size, double *vect)
void restoreStatus(const char filename[]="MTwist.conf")
static std::string engineName()
Definition: MTwistEngine.h:77
void setSeeds(const long *seeds, int)
void showStatus() const
void saveStatus(const char filename[]="MTwist.conf") const
std::vector< unsigned long > put() const
std::string name() const
Definition: MTwistEngine.cc:64
static const unsigned int VECTOR_STATE_SIZE
Definition: MTwistEngine.h:83
void setSeed(long seed, int)
static std::string beginTag()
Definition: DoubConv.h:17