Line data Source code
1 : /* +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
2 : Copyright (c) 2012-2018 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.org for more information.
6 :
7 : This file is part of plumed, version 2.
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 1457 : 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;
40 : bool switchGaussian;
41 : double saveGaussian;
42 : int iy;
43 : int iv[NTAB];
44 : int idum;
45 : std::string name;
46 : public:
47 : explicit 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 :
|