-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathRandom.cpp
More file actions
38 lines (30 loc) · 998 Bytes
/
Random.cpp
File metadata and controls
38 lines (30 loc) · 998 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
#include "Random.h"
std::mt19937 Random::engine((unsigned)time(nullptr));
float Random::nextFloat(float min, float max) {
std::uniform_real_distribution<float> dist(min, max);
return dist(engine);
}
float Random::nextFloat(float max) {
std::uniform_real_distribution<float> dist(0.f, max);
return dist(engine);
}
int Random::nextInt(int min, int max) {
std::uniform_int_distribution<int> dist(min, max);
return dist(engine);
}
int Random::nextInt(int max) {
std::uniform_int_distribution<int> dist(0, max);
return dist(engine);
}
int Random::nextDirection() {
std::uniform_int_distribution<int> dist(0, 1);
return dist(engine) == 0 ? 1 : -1;
}
unsigned Random::nextUInt(unsigned min, unsigned max) {
std::uniform_int_distribution<unsigned> dist(min, max);
return dist(engine);
}
unsigned Random::nextUInt(unsigned max) {
std::uniform_int_distribution<unsigned> dist(0, max);
return dist(engine);
}