-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrandom.cpp
32 lines (28 loc) · 851 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
#include "random.h"
std::default_random_engine & global_urng( )
{
static std::default_random_engine u{};
return u;
}
void randomize( )
{
static std::random_device rd{};
global_urng().seed( rd() );
}
//[min, max]
int numAleatorio(int minimo, int maximo)
{
/*
-std=c++11 minimo requerido en las propiedades del compilador
DevCpp: Opciones de Proyecto (Ctrl+H) -> Argumentos para el programa -> C++ compiler, añadir -std=c++11
*/
static std::uniform_int_distribution<> d{};
using parm_t = decltype(d)::param_type;
return d( global_urng(), parm_t{minimo, maximo} );
}
double numAleatorioReal(double minimo, double maximo)
{
static std::uniform_real_distribution<> d{};
using parm_t = decltype(d)::param_type;
return d( global_urng(), parm_t{minimo, maximo} );
}