-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathRandom.cpp
33 lines (24 loc) · 914 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 Abel Naya Forcano, 544125
* @date Enero 2020
* @coms Informática Gráfica - Trabajo 4: Path tracer
******************************************************************************/
#include "Random.hpp"
#include "Color.hpp"
#include "Texture.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, nextafter(1.0f, MAXFLOAT));
float random_zero_one() {
return dist(generator);
}
int random_zero_n(int n) {
return uniform_int_distribution<>(0, n)(generator);
}
float random_float(float min, float max) {
return uniform_real_distribution<float>(min, nextafter(max, MAXFLOAT))(generator);
}