-
Notifications
You must be signed in to change notification settings - Fork 3
/
random.h
executable file
·76 lines (59 loc) · 1.78 KB
/
random.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
// *******************************
// Various Random Number Utilities
//
// RDB 2/95
// *******************************
#pragma once
#include "VectorMatrix.h"
#include <fstream>
using namespace std;
// Global defines for ran1
#define IA 16807
#define IM 2147483647
#define AM (1.0/IM)
#define IQ 127773
#define IR 2836
#define NTAB 32
#define NDIV (1+(IM-1)/NTAB)
#define EPS 1.2e-7
#define RNMX (1.0-EPS)
// Functions to manipulate the global random state for backward compatibility
void SetRandomSeed(long seed);
long GetRandomSeed(void);
void WriteRandomState(ostream& os);
void BinaryWriteRandomState(ofstream& bofs);
void ReadRandomState(istream& is);
void BinaryReadRandomState(ifstream& bifs);
double UniformRandom(double min,double max);
int UniformRandomInteger(int min,int max);
double GaussianRandom(double mean, double variance);
void RandomUnitVector(TVector<double> &v);
int ProbabilisticChoice(double prob);
// The RandomState class declaration
class RandomState {
public:
// The constructor
RandomState(long seed = 0) {SetRandomSeed(seed); gaussian_flag = 0;};
// The destructor
~RandomState() {};
// Accessors
void SetRandomSeed(long seed);
long GetRandomSeed(void);
// Helper functions
double ran1(void);
void GenerateNormals(void);
// Return random deviates
double UniformRandom(double min,double max);
int UniformRandomInteger(int min,int max);
double GaussianRandom(double mean, double variance);
void RandomUnitVector(TVector<double> &v);
int ProbabilisticChoice(double prob);
// Input/Output
void WriteRandomState(ostream& os);
void BinaryWriteRandomState(ofstream& bofs);
void ReadRandomState(istream& is);
void BinaryReadRandomState(ifstream& bifs);
long seed, idum, iy, iv[NTAB];
int gaussian_flag;
double gX1, gX2;
};