-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathRandom.cpp
More file actions
45 lines (37 loc) · 808 Bytes
/
Random.cpp
File metadata and controls
45 lines (37 loc) · 808 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
/** @file Random.cpp */
/** @brief Finished */
#include "Random.h"
#include <ctime>
#include <cstdlib>
Random::Random()
{
}
void Random::initialize()
{
srand((int) time(NULL));
}
void Random::quit()
{
}
/**
* @brief Returns a random integer number in [0, x[ with a uniform distribution.
*
* This is equivalent to: Random::get_number(0, x).
*
* @param x the superior bound
* @return a random integer number in [0, x[
*/
int Random::get_number(unsigned int x)
{
return (int) ((double) x * rand() / (RAND_MAX + 1.0));
}
/**
* @brief Returns a random integer number in [x, y[ with a uniform distribution.
* @param x the inferior bound
* @param y the superior bound
* @return a random integer number in [x, y[
*/
int Random::get_number(unsigned int x, unsigned int y)
{
return x + get_number(y - x);
}