-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrandNumbers.cpp
More file actions
59 lines (48 loc) · 1001 Bytes
/
randNumbers.cpp
File metadata and controls
59 lines (48 loc) · 1001 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
50
51
52
53
54
55
56
57
58
// ********************* Random Numbers Source Code ************************//
#include <iostream>
using namespace std;
void setSeed(int seedVal)
{
srand(seedVal);
}
int chooseInt(int min,int max)
{
int uniRand;
uniRand = rand() % ((max + 1) - min) + min;
return (uniRand);
}
double chooseDouble(double min,double max)
{
double RandD;
RandD = min + ((max - min) * rand())/ (RAND_MAX + 1.0);
return (RandD);
}
double getRand()
{
return rand() / double(RAND_MAX);
}
int getNormal(float mean,float stdDev)
{
const int NUM_UNIFORM = 12;
const int MAX = 1000;
const float ORIGINAL_MEAN = NUM_UNIFORM * 0.5;
float sum;
int i;
float standardNormal;
float 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);
}