All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
Random.h
Go to the documentation of this file.
1 /* +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
2  Copyright (c) 2013 The plumed team
3  (see the PEOPLE file at the root of the distribution for a list of names)
4 
5  See http://www.plumed-code.org for more information.
6 
7  This file is part of plumed, version 2.0.
8 
9  plumed is free software: you can redistribute it and/or modify
10  it under the terms of the GNU Lesser General Public License as published by
11  the Free Software Foundation, either version 3 of the License, or
12  (at your option) any later version.
13 
14  plumed is distributed in the hope that it will be useful,
15  but WITHOUT ANY WARRANTY; without even the implied warranty of
16  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17  GNU Lesser General Public License for more details.
18 
19  You should have received a copy of the GNU Lesser General Public License
20  along with plumed. If not, see <http://www.gnu.org/licenses/>.
21 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ */
22 #ifndef __PLUMED_tools_Random_h
23 #define __PLUMED_tools_Random_h
24 
25 #include <string>
26 #include <iosfwd>
27 
28 namespace PLMD{
29 
30 /// \ingroup TOOLBOX
31 class Random{
32  static const int IA=16807,IM=2147483647,IQ=127773,IR=2836,NTAB=32;
33  static const int NDIV=(1+(IM-1)/NTAB);
34  static const double EPS;
35  static const double AM;
36  static const double RNMX;
37  static const double fact;
38  static const std::string noname;
39  bool incPrec;
41  double saveGaussian;
42  int iy;
43  int iv[NTAB];
44  int idum;
45  std::string name;
46 public:
47  Random(const std::string & name=noname);
48  void setSeed(int idum);
49  double RandU01();
50  double U01();
51  double U01d();
52  void WriteStateFull(std::ostream &)const;
53  void ReadStateFull (std::istream &);
54  void fromString(const std::string & str);
55  void toString(std::string & str)const;
56  friend std::ostream & operator<<(std::ostream & out,const Random & rng){
57  rng.WriteStateFull(out); return out;
58  }
59  friend std::istream & operator>>(std::istream & in,Random & rng){
60  rng.ReadStateFull(in); return in;
61  }
62  double Gaussian();
63  void IncreasedPrecis(bool i){incPrec=i;}
64 };
65 
66 }
67 
68 #endif
69 
void toString(std::string &str) const
Definition: Random.cpp:117
void fromString(const std::string &str)
Definition: Random.cpp:126
double saveGaussian
Definition: Random.h:41
double U01()
Definition: Random.cpp:74
static const double AM
Definition: Random.h:35
friend std::ostream & operator<<(std::ostream &out, const Random &rng)
Definition: Random.h:56
double U01d()
Definition: Random.cpp:65
static const double fact
Definition: Random.h:37
void setSeed(int idum)
Definition: Random.cpp:51
void WriteStateFull(std::ostream &) const
Definition: Random.cpp:98
bool incPrec
Definition: Random.h:39
std::string name
Definition: Random.h:45
void ReadStateFull(std::istream &)
Definition: Random.cpp:109
static const int IQ
Definition: Random.h:32
int idum
Definition: Random.h:44
void IncreasedPrecis(bool i)
Definition: Random.h:63
static const int NDIV
Definition: Random.h:33
Random(const std::string &name=noname)
Definition: Random.cpp:36
static const int IR
Definition: Random.h:32
static const int IA
Definition: Random.h:32
static const int IM
Definition: Random.h:32
friend std::istream & operator>>(std::istream &in, Random &rng)
Definition: Random.h:59
bool switchGaussian
Definition: Random.h:40
static const int NTAB
Definition: Random.h:32
static const double EPS
Definition: Random.h:34
double RandU01()
Definition: Random.cpp:56
double Gaussian()
Definition: Random.cpp:140
static const double RNMX
Definition: Random.h:36
int iy
Definition: Random.h:42
static const std::string noname
Definition: Random.h:38
int iv[NTAB]
Definition: Random.h:43