-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrandom.cpp
More file actions
49 lines (45 loc) · 797 Bytes
/
random.cpp
File metadata and controls
49 lines (45 loc) · 797 Bytes
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
#include <cstdlib>
using namespace std;
void setSeed(
const int seedVal
)
{
srand(seedVal);
}
int getUniform(
const int min,
const int max
)
{
int uniRand;
uniRand = rand() % ((max + 1) - min) + min;
return (uniRand);
}
int getNormal(
const double mean,
const double stdDev
)
{
const int NUM_UNIFORM = 12;
const int MAX = 1000;
const double ORIGINAL_MEAN = NUM_UNIFORM * 0.5;
double sum;
int i;
double standardNormal;
double newNormal;
int uni;
sum = 0;
for (i = 0; i < NUM_UNIFORM; i++)
{
uni = rand() % (MAX + 1);
sum += uni;
}
sum = sum / MAX;
standardNormal = sum - ORIGINAL_MEAN;
newNormal = mean + stdDev * standardNormal;
if (newNormal < 0)
{
newNormal *= - 1;
}
return ((int)newNormal);
}