NetDEM v1.0
Loading...
Searching...
No Matches
utils_distributions.hpp
Go to the documentation of this file.
1#pragma once
2
3#include "distribution.hpp"
4#include <random>
5
6namespace netdem {
7
16public:
20 RandomEngine(const RandomEngine &) = delete;
21
26
36 static RandomEngine instance;
37 return instance;
38 }
39
51 double GetUniformDistribution(double bound_min, double bound_max) {
52 std::random_device rd;
53 std::mt19937 mt_eng = std::mt19937(rd());
54 std::uniform_real_distribution<double> real_dist(bound_min, bound_max);
55
56 return real_dist(mt_eng);
57 }
58
71 VecXT<double> GetUniformDistribution(double bound_min, double bound_max,
72 int num) {
73 std::random_device rd;
74 std::mt19937 mt_eng = std::mt19937(rd());
75 std::uniform_real_distribution<double> real_dist(bound_min, bound_max);
76
77 VecXT<double> num_list(num, 0);
78
79 for (int i = 0; i < num; i++) {
80 num_list[i] = real_dist(mt_eng);
81 }
82
83 return num_list;
84 }
85
86private:
93 RandomEngine() {}
94};
95
96} // namespace netdem
A class for generating random numbers.
Definition utils_distributions.hpp:15
double GetUniformDistribution(double bound_min, double bound_max)
Generate a random number from a uniform distribution.
Definition utils_distributions.hpp:51
static RandomEngine & GetInstance()
Get a reference to the singleton RandomEngine instance.
Definition utils_distributions.hpp:35
RandomEngine(const RandomEngine &)=delete
Delete copy constructor.
VecXT< double > GetUniformDistribution(double bound_min, double bound_max, int num)
Generate a list of random numbers from a uniform distribution.
Definition utils_distributions.hpp:71
RandomEngine & operator=(const RandomEngine &)=delete
Delete copy assignment operator.
Definition bond_entry.hpp:7
std::vector< T > VecXT
Definition utils_macros.hpp:31