-
Notifications
You must be signed in to change notification settings - Fork 7
/
Random.cpp
33 lines (25 loc) · 908 Bytes
/
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
/******************************************************************************
* @file Random.cpp
* @author Andrés Gavín Murillo, 716358
* @author Rubén Rodríguez Esteban, 737215
* @date Mayo 2020
* @coms Videojuegos - OutRun
******************************************************************************/
#include "Random.hpp"
#include <random>
using namespace std;
static thread_local random_device rd;
static thread_local std::mt19937 generator(rd());
static thread_local uniform_real_distribution<float> dist(0.0f, 1.0f);
float random_zero_one() {
return dist(generator);
}
int random_zero_n(int n) {
return uniform_int_distribution<>(0, n)(generator);
}
int random_int(int min, int max) {
return uniform_int_distribution<int>(min, max)(generator);
}
float random_float(float min, float max) {
return uniform_real_distribution<float>(min, max)(generator);
}