BioinstSim  2
 All Classes Functions Variables
random.h
1 /* -*- Mode:C++ -*- */
2 
3 #ifndef RANDOM_H
4 #define RANDOM_H
5 
6 #include <stdlib.h>
7 #include <sys/time.h>
8 
9 using namespace std;
10 
11 class Random {
12 private:
13  /* constants for a pseudo-random number generator,
14  for details see numerical recipes in C */
15 
16  // IM = IA * IQ + IR
17  static const int IA = 16807; // 75 (prime root of IM)
18  static const int IM = 2147483647; // 231 - 1 (biggest prime in 32bit)
19  static const double AM;
20  static const int IQ = 127773; // quot (IM / IA)
21  static const int IR = 2836; // remainder (IM mod IA)
22 
23  static double ran01(long *idum);
24 
25 public:
26 
27  static long int seed;
28  static void set_seed(long int s) {Random::seed = s;}
29  static long int set_seed_usec();
30 
31  // uniformly distributed double in [0,1)
32  static double nextDouble() { return ran01(&seed);}
33 
34  // uniformly distributed double in [lbound, ubound)
35  static double nextDouble(double lbound, double ubound);
36 
37  // uniformly distributed double in [0, ubound)
38  static double nextDouble(double ubound);
39 
40  // uniformly distributed integer in {lbound, ..., ubound-1}
41  static int nextInt(int lbound, int ubound);
42 
43  // uniformly distributed integer in {0, ..., ubound-1}
44  static int nextInt(int ubound);
45 
46  // N(0,1) distributed double
47  static double nextNormGaussian();
48 
49  // N(mean, sigma2) distributed double
50  static double nextGaussian(double mean, double sigma);
51 
52  // uniformly distributed boolean
53  static bool nextBoolean();
54 
55 };
56 
57 
58 
59 #endif