-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathRandomNumGenerator.cpp
40 lines (36 loc) · 1.11 KB
/
RandomNumGenerator.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
//
// Created by danny on 2018-11-20.
//
#include "RandomNumGenerator.hpp"
/**
* Gets an instance of the singleton class
* @return RandomNumGenerator object
*/
RandomNumGenerator &RandomNumGenerator::getInstance() {
static RandomNumGenerator random;
return random;
}
/**
* Default constructor setting the generator
*/
RandomNumGenerator::RandomNumGenerator() : generator(rd()) { }
/**
* Generates a random integer in the supplied range
* @param minInclusive minimum value
* @param maxInclusive maximum value
* @return random integer in range
*/
int RandomNumGenerator::getIntegerInRange(int minInclusive, int maxInclusive) {
uniform_int_distribution<int> distribution(minInclusive, maxInclusive);
return distribution(generator);
}
/**
* Generates a random double in the supplied range
* @param minInclusive minimum value
* @param maxInclusive maximum value
* @return random double in range
*/
double RandomNumGenerator::getRealInRange(double minInclusive, double maxInclusive) {
uniform_real_distribution<double> distribution(minInclusive, maxInclusive);
return distribution(generator);
}