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

MTwistEngine.h

Go to the documentation of this file.
00001 // $Id: MTwistEngine.h,v 1.5 2010/06/16 17:24:53 garren Exp $
00002 // -*- C++ -*-
00003 //
00004 // -----------------------------------------------------------------------
00005 //                             HEP Random
00006 //                        --- MTwistEngine ---
00007 //                          class header file
00008 // -----------------------------------------------------------------------
00009 // A "fast, compact, huge-period generator" based on M. Matsumoto and 
00010 // T. Nishimura, "Mersenne Twister: A 623-dimensionally equidistributed 
00011 // uniform pseudorandom number generator", to appear in ACM Trans. on
00012 // Modeling and Computer Simulation.  It is a twisted GFSR generator
00013 // with a Mersenne-prime period of 2^19937-1, uniform on open interval (0,1)
00014 // For further information, see http://www.math.keio.ac.jp/~matumoto/emt.html
00015 // =======================================================================
00016 // Ken Smith      - Started initial draft: 14th Jul 1998
00017 //                - Optimized to get pow() out of flat() method: 21st Jul
00018 //                - Added conversion operators:  6th Aug 1998
00019 // M Fischler     - Changes in way powers of two are kept: 16-Sep-1998
00020 // Mark Fischler  - Methods for distrib. instance save/restore 12/8/04    
00021 // Mark Fischler    methods for anonymous save/restore 12/27/04    
00022 // =======================================================================
00023 
00024 #ifndef MTwistEngine_h
00025 #define MTwistEngine_h
00026 
00027 #include "CLHEP/Random/defs.h"
00028 #include "CLHEP/Random/RandomEngine.h"
00029 
00030 namespace CLHEP {
00031 
00036 class MTwistEngine : public HepRandomEngine {
00037 
00038 public:
00039 
00040   MTwistEngine();
00041   MTwistEngine( long seed );
00042   MTwistEngine( int rowIndex, int colIndex );
00043   MTwistEngine( std::istream & is );
00044   virtual ~MTwistEngine();
00045   // Constructors and destructor.
00046 
00047   double flat();
00048   // Returns a pseudo random number between 0 and 1 (excluding the end points).
00049 
00050   void flatArray(const int size, double* vect);
00051   // Fills an array "vect" of specified size with flat random values.
00052 
00053   void setSeed(long seed, int);
00054   // Sets the state of the algorithm according to seed.
00055 
00056   void setSeeds(const long * seeds, int);
00057   // Sets the state of the algorithm according to the zero terminated
00058   // array of seeds. It is allowed to ignore one or many seeds in this array.
00059 
00060   void saveStatus( const char filename[] = "MTwist.conf") const;
00061   // Saves the current engine status in the named file
00062 
00063   void restoreStatus( const char filename[] = "MTwist.conf" );
00064   // Reads from named file the the last saved engine status and restores it.
00065 
00066   void showStatus() const;
00067   // Dumps the current engine status on the screen.
00068 
00069   operator float();     // returns flat, without worrying about filling bits
00070   operator unsigned int(); // 32-bit flat, quickest of all
00071 
00072   virtual std::ostream & put (std::ostream & os) const;
00073   virtual std::istream & get (std::istream & is);
00074   static  std::string beginTag ( );
00075   virtual std::istream & getState ( std::istream & is );
00076 
00077   std::string name() const;
00078   static std::string engineName() {return "MTwistEngine";}
00079 
00080   std::vector<unsigned long> put () const;
00081   bool get (const std::vector<unsigned long> & v);
00082   bool getState (const std::vector<unsigned long> & v);
00083 
00084   static const unsigned int VECTOR_STATE_SIZE = 626;
00085   
00086 private:
00087 
00088   unsigned int mt[624];
00089   int count624;
00090 
00091   enum{ NminusM = 227, M = 397, N = 624};
00092   static int numEngines;
00093   static int maxIndex;
00094 
00095 }; // MTwistEngine
00096 
00097 }  // namespace CLHEP
00098 
00099 #ifdef ENABLE_BACKWARDS_COMPATIBILITY
00100 //  backwards compatibility will be enabled ONLY in CLHEP 1.9
00101 using namespace CLHEP;
00102 #endif
00103 
00104 #endif // MTwistEngine_h

Generated on 15 Nov 2012 for CLHEP by  doxygen 1.4.7