-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathRandomNumbers.cpp
50 lines (43 loc) · 1.19 KB
/
RandomNumbers.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
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
/**
* @file RandomNumbers.cpp
* @class RandomNumbers RandomNumbers.h
*
* @brief Provides random number generation
*
* @license This file is distributed under the BSD Open Source License.
* See LICENSE.TXT for details.
*/
#include "RandomNumbers.h"
#include <chrono>
using namespace std::chrono;
/**
* @brief Constructor for RandomNumbers class
**/
RandomNumbers::RandomNumbers()
: engine(static_cast<uint64_t> (system_clock::to_time_t(system_clock::now()))),
zeroToOne(0.0, 1.0), zeroToTwoPi(0.0, 2.0*M_PI) {}
/**
* @brief Uniformly distributed random numbers between 0 - 1
*
* @return Number between 0 - 1
**/
const double RandomNumbers::uniformZeroToOne() {
return zeroToOne(engine);
}
/**
* @brief Uniformly distributed random numbers between 0 - 2*Pi
*
* @return Number between 0 - 2*pi
**/
const double RandomNumbers::uniformZeroToTwoPi() {
return zeroToTwoPi(engine);
}
/**
* @brief Standard gaussian distributed random numbers
*
* @param[in] dist Object that produces values according to a normal distribution
* @return Number with gaussian distribution with mean 0 and std dev 1
**/
const double RandomNumbers::gaussian(std::normal_distribution<double> &dist) {
return dist(engine);
}