-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrandomNumberGenerator.cpp
More file actions
53 lines (46 loc) · 1.21 KB
/
Copy pathrandomNumberGenerator.cpp
File metadata and controls
53 lines (46 loc) · 1.21 KB
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
#include "randomNumberGenerator.h"
#include <time.h>
#ifdef R1
#ifndef R3
unsigned int randomNumberGenerator::nextInt() {
int hi = seed / qqq;
int lo = seed % qqq;
int test = aaa * lo - rrr * hi;
if(test > 0)
seed = test;
else
seed = test + mmm;
return seed - 1;
}
int randomNumberGenerator::seed = SEED_DEFAULT_VALUE;
#else
#include <iostream>
unsigned int randomNumberGenerator::nextInt() {
static unsigned int x=123456789, y=362436069, z=521288629;
unsigned int t;
x ^= x << 16;
x ^= x >> 5;
x ^= x << 1;
t = x;
x = y;
y = z;
z = t ^ x ^ y;
//std::cout << x << " " << y << " " << z << std::endl;
return z;
//return rand() * 0x7fff + rand();
//return rand();
//return time(NULL);
}
#endif
double randomNumberGenerator::nextReal() {
return randomNumberGenerator::nextInt() / (double)rand_max_val;
}
#endif
#ifdef R2
#include <limits>
using namespace std;
mt19937 randomNumberGenerator::rng(3u);
uniform_int_distribution<> randomNumberGenerator::uInt32dist(0, numeric_limits<int>::max());
variate_generator<mt19937&, uniform_int_distribution<>> randomNumberGenerator::nextInt(rng, uInt32dist);
uniform_01<mt19937> randomNumberGenerator::nextReal(rng);
#endif