Bridge++  Version 1.5.4
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
randomNumbers_Mseries.h
Go to the documentation of this file.
1 
14 #ifndef RANDOMNUMBERS_MSERIES_INCLUDED
15 #define RANDOMNUMBERS_MSERIES_INCLUDED
16 
17 #include <assert.h>
18 #include <cmath>
19 #include <fstream>
20 #include <iostream>
21 #include <string>
22 
23 #include "randomNumbers.h"
25 
26 #include "IO/bridgeIO.h"
27 using Bridge::vout;
28 
30 
47 {
48  // static const double Fnorm = 4.656612870908988e-10;
49  static const double Fnorm;
50 
51  public:
52  static const std::string class_name;
53 
54  private:
55  static const int Np = 521, Nq = 32;
56  int w[Np];
57  int jr, kr;
58 
59  double sq2r;
60  double pi, pi2;
61 
62  public:
63  RandomNumbers_Mseries(const int ndelay)
64  {
65  initset(ndelay);
66  }
67 
68  RandomNumbers_Mseries(const std::string& filename)
69  {
70  read_file(filename);
71  }
72 
73  double get()
74  {
75  w[jr] = w[jr] ^ w[kr];
76  double rw = w[jr] * Fnorm;
77  jr = jr + 1;
78  if (jr >= Np) jr = jr - Np;
79  kr = kr + 1;
80  if (kr >= Np) kr = kr - Np;
81  return rw;
82  }
83 
84  void write_file(const std::string&);
85  void read_file(const std::string&);
86 
87  void reset(unsigned long seed);
88 
89  private:
90 
91  void initset(const int ndelay);
92 
93  void delay3(const int ndelay);
94 
95 #ifdef USE_FACTORY
96  private:
97  static RandomNumbers *create_object_with_int(const int& iseed)
98  {
99  return new RandomNumbers_Mseries(iseed);
100  }
101 
102  static RandomNumbers *create_object_with_file(const std::string& filename)
103  {
104  return new RandomNumbers_Mseries(filename);
105  }
106 
107  public:
108  static bool register_factory()
109  {
110  bool init1 = RandomNumbers::Factory_int::Register("Mseries", create_object_with_int);
111  bool init2 = RandomNumbers::Factory_file::Register("Mseries", create_object_with_file);
112 
113  return init1 && init2;
114  }
115 #endif
116 };
117 #endif
Random number generator base on M-series.
BridgeIO vout
Definition: bridgeIO.cpp:503
void read_file(const std::string &)
save and load random number status.
RandomNumbers_Mseries(const int ndelay)
void delay3(const int ndelay)
void initset(const int ndelay)
void reset(unsigned long seed)
reset state with new seed.
void write_file(const std::string &)
RandomNumbers_Mseries(const std::string &filename)
Base class of random number generators.
Definition: randomNumbers.h:43
static const double Fnorm
initialized in .cpp file.
static const std::string class_name