Bridge++  Ver. 1.2.x
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
randomNumbers_MT19937.h
Go to the documentation of this file.
1 
14 #ifndef RANDOMNUMBERS_MT19937_INCLUDED
15 #define RANDOMNUMBERS_MT19937_INCLUDED
16 
17 //==========================================================
18 // Random number generator.
19 // MT19937 random number generator.
20 // Original version in C was written by
21 // Takuji Nishimura and Makoto Matsumoto.
22 // See URL http://www.math.sci.hiroshima-u.ac.jp/~m-mat/MT/MT2002/mt19937ar.html
23 //
24 // 25 Dec 2004 H.Matsufuru
25 //==========================================================
26 
27 #include <cmath>
28 #include <string>
29 #include <vector>
30 #include <assert.h>
31 #include <iostream>
32 #include <fstream>
33 #include <vector>
34 using std::vector;
35 #include <string>
36 using std::string;
37 
38 #include "randomNumbers.h"
39 
40 #include "bridgeIO.h"
41 using Bridge::vout;
42 
44 {
45  static const std::string class_name;
46 
47  public:
48  RandomNumbers_MT19937(int s);
49  //RandomNumbers_MT19937(unsigned long s = 5489UL);
50  RandomNumbers_MT19937(unsigned long s);
51  RandomNumbers_MT19937(std::vector<unsigned long>& key);
52  RandomNumbers_MT19937(const std::string& filename);
53 
55 
56  double get() { return randDouble2(); }
57 
58  void writefile(const std::string&);
59  void readfile(const std::string&);
60 
61  private:
62  void init(unsigned long s);
63  void init(unsigned long s, std::vector<unsigned long>& key);
64 
65  void nextState() const;
66  unsigned long twist(unsigned long u, unsigned long v) const;
67 
68  // return [0,0xffffffff]
69  unsigned long randInt32() const;
70 
71  // return [0,0x7fffffff]
72  long randInt31() const;
73 
74  // return [0,1] random number
75  double randDouble1() const;
76 
77  // return [0,1) random number
78  double randDouble2() const;
79 
80  // return (0,1) random number
81  double randDouble3() const;
82 
83  // return [0,1) random number with 53-bit resolution
84  double randRes53() const;
85 
86  enum { N=624, M=397 };
87 
88  mutable int m_left;
89  mutable unsigned long m_state[N];
90  mutable unsigned long *m_next;
91 };
92 #endif
BridgeIO vout
Definition: bridgeIO.cpp:207
void writefile(const std::string &)
static const std::string class_name
unsigned long twist(unsigned long u, unsigned long v) const
void readfile(const std::string &)
void init(unsigned long s)
unsigned long randInt32() const
Base class of random number generators.
Definition: randomNumbers.h:40