CLHEP VERSION Reference Documentation
   
CLHEP Home Page     CLHEP Documentation     CLHEP Bug Reports

Matrix/CLHEP/Random/MTwistEngine.h
Go to the documentation of this file.
1// $Id: MTwistEngine.h,v 1.5 2010/06/16 17:24:53 garren Exp $
2// -*- C++ -*-
3//
4// -----------------------------------------------------------------------
5// HEP Random
6// --- MTwistEngine ---
7// class header file
8// -----------------------------------------------------------------------
9// A "fast, compact, huge-period generator" based on M. Matsumoto and
10// T. Nishimura, "Mersenne Twister: A 623-dimensionally equidistributed
11// uniform pseudorandom number generator", to appear in ACM Trans. on
12// Modeling and Computer Simulation. It is a twisted GFSR generator
13// with a Mersenne-prime period of 2^19937-1, uniform on open interval (0,1)
14// For further information, see http://www.math.keio.ac.jp/~matumoto/emt.html
15// =======================================================================
16// Ken Smith - Started initial draft: 14th Jul 1998
17// - Optimized to get pow() out of flat() method: 21st Jul
18// - Added conversion operators: 6th Aug 1998
19// M Fischler - Changes in way powers of two are kept: 16-Sep-1998
20// Mark Fischler - Methods for distrib. instance save/restore 12/8/04
21// Mark Fischler methods for anonymous save/restore 12/27/04
22// =======================================================================
23
24#ifndef MTwistEngine_h
25#define MTwistEngine_h
26
27#include "CLHEP/Random/defs.h"
28#include "CLHEP/Random/RandomEngine.h"
29
30namespace CLHEP {
31
37
38public:
39
41 MTwistEngine( long seed );
42 MTwistEngine( int rowIndex, int colIndex );
43 MTwistEngine( std::istream & is );
44 virtual ~MTwistEngine();
45 // Constructors and destructor.
46
47 double flat();
48 // Returns a pseudo random number between 0 and 1 (excluding the end points).
49
50 void flatArray(const int size, double* vect);
51 // Fills an array "vect" of specified size with flat random values.
52
53 void setSeed(long seed, int);
54 // Sets the state of the algorithm according to seed.
55
56 void setSeeds(const long * seeds, int);
57 // Sets the state of the algorithm according to the zero terminated
58 // array of seeds. It is allowed to ignore one or many seeds in this array.
59
60 void saveStatus( const char filename[] = "MTwist.conf") const;
61 // Saves the current engine status in the named file
62
63 void restoreStatus( const char filename[] = "MTwist.conf" );
64 // Reads from named file the the last saved engine status and restores it.
65
66 void showStatus() const;
67 // Dumps the current engine status on the screen.
68
69 operator float(); // returns flat, without worrying about filling bits
70 operator unsigned int(); // 32-bit flat, quickest of all
71
72 virtual std::ostream & put (std::ostream & os) const;
73 virtual std::istream & get (std::istream & is);
74 static std::string beginTag ( );
75 virtual std::istream & getState ( std::istream & is );
76
77 std::string name() const;
78 static std::string engineName() {return "MTwistEngine";}
79
80 std::vector<unsigned long> put () const;
81 bool get (const std::vector<unsigned long> & v);
82 bool getState (const std::vector<unsigned long> & v);
83
84 static const unsigned int VECTOR_STATE_SIZE = 626;
85
86private:
87
88 unsigned int mt[624];
89 int count624;
90
91 enum{ NminusM = 227, M = 397, N = 624};
92 static int numEngines;
93 static int maxIndex;
94
95}; // MTwistEngine
96
97} // namespace CLHEP
98
99#ifdef ENABLE_BACKWARDS_COMPATIBILITY
100// backwards compatibility will be enabled ONLY in CLHEP 1.9
101using namespace CLHEP;
102#endif
103
104#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")
void setSeeds(const long *seeds, int)
void showStatus() const
void saveStatus(const char filename[]="MTwist.conf") const
std::vector< unsigned long > put() const
static const unsigned int VECTOR_STATE_SIZE
std::string name() const
Definition: MTwistEngine.cc:53
void setSeed(long seed, int)
static std::string beginTag()