Langmuir
Simulation
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
rand.h
Go to the documentation of this file.
1 #ifndef _RAND_H
2 #define _RAND_H
3 
4 #include <QObject>
5 #include <QDataStream>
6 #include <QTextStream>
7 
8 #ifndef Q_MOC_RUN
9 
10 #if __GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 6)
11 #pragma GCC diagnostic push
12 #pragma GCC system_header
13 #endif
14 
15 #include <boost/random.hpp>
16 
17 #if __GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 6)
18 #pragma GCC diagnostic pop
19 #endif
20 
21 #endif
22 
23 #include <ctime>
24 
25 namespace LangmuirCore
26 {
27 
31 class Random : public QObject
32 {
33 private:
34  Q_OBJECT
35  Q_DISABLE_COPY(Random)
36 
37 public:
44  Random(quint64 seed=0, QObject *parent=0);
45 
49  ~Random();
50 
54  quint64 seed();
55 
62  void seed(quint64 seed);
63 
67  double random();
68 
72  double range(const double low=0.0, const double high=1.0);
73 
79  double normal(const double mean, const double sigma);
80 
84  int integer(const int low=0, const int high=1);
85 
91  bool metropolis(double energyChange, double inversekT);
92 
101  bool metropolisWithCoupling(double energyChange, double inversekT, double coupling);
102 
106  bool chooseYes(double percent);
107 
111  bool chooseNo(double percent);
112 
117  friend QDataStream& operator<<(QDataStream& stream, Random& random);
118 
123  friend QDataStream& operator>>(QDataStream& stream, Random& random);
124 
129  friend QTextStream& operator<<(QTextStream& stream, Random& random);
130 
135  friend QTextStream& operator>>(QTextStream& stream, Random& random);
136 
140  friend std::ostream& operator<<(std::ostream& stream, Random& random);
141 
145  friend std::istream& operator>>(std::istream& stream, Random& random);
146 
147 private:
151  boost::mt19937 *twister;
152 
156  boost::variate_generator<boost::mt19937&, boost::uniform_01<double> >* generator01;
157 
161  quint64 m_seed;
162 };
163 
164 }
165 #endif
A class to generate random numbers.
Definition: rand.h:31
double normal(const double mean, const double sigma)
Generate a random double from the normal distribution.
boost::variate_generator< boost::mt19937 &, boost::uniform_01< double > > * generator01
The underlying generator coupled to the uniform distribution on [0,1].
Definition: rand.h:156
~Random()
Destroy objects.
bool metropolis(double energyChange, double inversekT)
Randomly choose yes using a Boltzmann factor.
int integer(const int low=0, const int high=1)
Generate a random int from the uniform distribution [low, high].
quint64 seed()
Get the seed that was used.
Random(quint64 seed=0, QObject *parent=0)
Random.
double range(const double low=0.0, const double high=1.0)
Generate a random double from the uniform distribution [low, high].
friend QDataStream & operator>>(QDataStream &stream, Random &random)
Load the random state from a QDataStream Possibly Broken.
quint64 m_seed
The seed used to start the generator.
Definition: rand.h:161
double random()
Generate a random double from the uniform distribution [0, 1].
boost::mt19937 * twister
The underlying random number generator.
Definition: rand.h:151
Definition: agent.h:12
bool chooseNo(double percent)
Randomly choose no a percent of the time.
friend QDataStream & operator<<(QDataStream &stream, Random &random)
Output the random state to a QDataStream Possibly Broken.
bool metropolisWithCoupling(double energyChange, double inversekT, double coupling)
Randomly choose yes using a Boltzmann factor and coupling constant.
bool chooseYes(double percent)
Randomly choose yes a percent of the time.