npstat is hosted by Hepforge, IPPP Durham
NPStat  5.10.0
MersenneTwister.hh
Go to the documentation of this file.
1 #ifndef NPSTAT_MERSENNETWISTER_HH_
2 #define NPSTAT_MERSENNETWISTER_HH_
3 
4 /*!
5 // \file MersenneTwister.hh
6 //
7 // \brief A wrapper for the Mersenne Twister generator of pseudo-random numbers
8 //
9 // Author: I. Volobouev
10 //
11 // October 2010
12 */
13 
14 #include "geners/CPP11_auto_ptr.hh"
16 
17 namespace npstat {
18  namespace Private {
19  class MTRand;
20  }
21 
22  /**
23  // Generator of pseudo-random numbers (with period 2^19937-1). Based on
24  // the interface written by Richard J. Wagner to the original Mersenne
25  // Twister.
26  //
27  // Reference:
28  // M. Matsumoto and T. Nishimura, "Mersenne Twister: A 623-Dimensionally
29  // Equidistributed Uniform Pseudo-Random Number Generator", ACM Transactions
30  // on Modeling and Computer Simulation, Vol. 8, No. 1, January 1998, pp 3-30.
31  */
33  {
34  public:
35  /** The default constructor will read /dev/urandom to get the seed */
37  explicit MersenneTwister(unsigned long seed);
39  virtual ~MersenneTwister();
40 
41  MersenneTwister& operator=(const MersenneTwister&);
42 
43  inline unsigned dim() const {return 1U;}
44  double operator()();
45 
46  private:
47  Private::MTRand* impl_;
48  };
49 
50  /*
51  // A convenience function which calls the default constructor of
52  // the MersenneTwister class if the seed is 0 and the constructor
53  // with the seed if the seed is not 0.
54  */
55  CPP11_auto_ptr<AbsRandomGenerator> make_MersenneTwister(unsigned long seed);
56 }
57 
58 #endif // NPSTAT_MERSENNETWISTER_HH_
Interface definition for pseudo- and quasi-random number generators.
Definition: MersenneTwister.hh:33
unsigned dim() const
Definition: MersenneTwister.hh:43
Definition: MersenneTwisterImpl.hh:73
Definition: AbsArrayProjector.hh:14
Definition: AbsRandomGenerator.hh:27