-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMT.cpp
More file actions
37 lines (32 loc) · 1.07 KB
/
MT.cpp
File metadata and controls
37 lines (32 loc) · 1.07 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
#include "MT.h"
#include <iostream>
// Constructor
MT::MT()
{
std::random_device rd; //Will be used to obtain a seed for the random number engine
std::seed_seq seed{ rd(), rd(), rd(), rd() }; // Set multiple random numbers for the seed
std::mt19937 gen(seed); //Standard mersenne_twister_engine seeded with multiples rd()
_MTGen = gen;
}
// Returns an instance of the MT
MT& MT::getInstance()
{
static std::unique_ptr<MT> instance(new MT());
return *instance;
}
// Returns a random number from a standard uniform distribution
double MT::rand_unif(std::mt19937& generator)
{
std::uniform_real_distribution<> unifDistrib(0.0, 1.0);
//return unifDistrib(generator);
return unifDistrib(getInstance()._MTGen);
}
// Returns a random number from a standard normal distribution
double MT::rand_norm(std::mt19937& generator)
{
std::normal_distribution<> normDistrib(0.0, 1.0);
//return normDistrib(generator);
return normDistrib(getInstance()._MTGen);
}
// Returns the generator of the instance
std::mt19937 MT::getGen() { return _MTGen; }