-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathRandom.cpp
More file actions
42 lines (34 loc) · 1.04 KB
/
Random.cpp
File metadata and controls
42 lines (34 loc) · 1.04 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
/* -------------------------------------------------
//
// 88888888888 ad88888ba 88888888888
// 88 d8" "8b 88
// 88 Y8, 88
// 88aaaaa ,adPPYYba, `Y8aaaaa, 88aaaaa
// 88""""" "" `Y8 `"""""8b, 88"""""
// 88 ,adPPPPP88 `8b 88
// 88 88, ,88 Y8a a8P 88
// 88 `"8bbdP"Y8 "Y88888P" 88888888888
//
//
Pedro {Paredes, Ribeiro} - DCC/FCUP
----------------------------------------------------
Random generator
---------------------------------------------------- */
#include "Random.h"
void Random::init(int s)
{
srand(s);
}
int Random::getInteger(int a, int b)
{
return a + rand() % (b - a + 1);
}
double Random::getDouble()
{
return rand() / (double) RAND_MAX;
}
bool Random::testProb(double p)
{
if (p > 0.9999999) return 1;
return (rand() / (double) RAND_MAX) < p;
}