-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathRandom.cpp
32 lines (27 loc) · 1.02 KB
/
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
#include "Random.h"
#include <cstdlib>
#include <ctime>
//-------------------------------------------------
// Seeds random to current time.
//-------------------------------------------------
void Random::initRandom() {
srand(time(nullptr));
}
//-------------------------------------------------
// Returns a random int in given boundaries.
//-------------------------------------------------
int Random::randomInt(int min, int max) {
return rand() % (max - min) + min;
}
//-------------------------------------------------
// Returns a random short int in given boundaries.
//-------------------------------------------------
short int Random::randomShortInt(short int min, short int max) {
return rand() % (max - min) + min;
}
//-------------------------------------------------
// Returns a random double in given boundaries.
//-------------------------------------------------
double Random::randomDouble(double min, double max) {
return (double) rand() / RAND_MAX * (max - min) + min;
}