forked from EcoSimIBM/EcoSim-Default
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathRandom.cpp
47 lines (36 loc) · 822 Bytes
/
Random.cpp
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
#ifndef RANDOM_CPP_
#define RANDOM_CPP_
#include <iostream>
#include <cstdlib>
#include <ctime>
#define RESET_RANDOM 100000
//#define SEED 5 //-- For test
#define SEED ((unsigned int) time(NULL))
using namespace std;
struct Random {
public:
long long num_randoms;
Random() {
srand(SEED);
num_randoms=0;
}
int next(int max) { //-- Random between 0 and max
int r = rand() % max;
num_randoms++;
if (num_randoms % RESET_RANDOM ==0)
srand(SEED);
return r;
}
int next(int min, int max) { //-- Random between min and max
int range = max - min + 1;
int r = rand() % range + min;
num_randoms++;
if (num_randoms % RESET_RANDOM ==0)
srand(SEED);
return r;
}
unsigned int getSEED(){
return SEED;
}
};
#endif