-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrandom.cpp
47 lines (37 loc) · 815 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
47
#include <iostream>
#include <math.h>
using namespace std;
const int a = 7141;
const int c = 54773;
const int mmod = 256200;
double getFlatRandom(int &inew) {
double mranflat = 0.;
inew = inew % mmod;
double aa = double(inew) / double(mmod);
mranflat = aa;
inew = a * inew + c;
return mranflat;
}
int main() {
int num;
cout << "Enter the number of loop iterations: ";
cin >> num;
int inew = 9989;
int histo[10] = {};
double atmp;
for (int i = 0; i < num; i++) {
atmp = getFlatRandom(inew);
if (i < 10) {
cout << atmp << endl;
}
histo[int(atmp * 10)]++;
}
for (int i = 0; i < num; i++) {
cout << i << ": ";
for (int j = 0; j < int((double(100 * histo[i]) / double(num)) + 0.5); j++) {
cout << "=";
}
cout << endl;
}
return 0;
}