-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathRand.cpp
More file actions
55 lines (43 loc) · 1.06 KB
/
Rand.cpp
File metadata and controls
55 lines (43 loc) · 1.06 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
54
55
/**
* \file Rand.cpp
* \brief Random number generations
*/
#include <StdStream/StdStream.h>
#include <StdTest/StdTest.h>
#include <Stl.h>
//--------------------------------------------------------------------------------------------------
// Name: random1()
// Desc: Generates a random number between specified min/max boundaries
int
random1(int nMin, int nMax)
{
int nRange = nMax - nMin;
int nNum = rand() % nRange;
return nNum + nMin;
}
//--------------------------------------------------------------------------------------------------
int main(int, char **)
{
int i = 0;
// Seed the random-number generator with the current time
// so that the numbers will be different every time we run.
srand((unsigned)time(NULL));
std::cout << "Using Random1 whith typical modulus ranging" << std::endl << std::endl;
for (i = 0; i < 10; i ++) {
std::cout << random1(1, 100) << std::endl;
}
return EXIT_SUCCESS;
}
//--------------------------------------------------------------------------------------------------
#if OUTPUT
84
6
21
56
5
8
20
42
62
63
#endif