libscnumerics/src/random.cpp

24 lines
606 B
C++
Raw Normal View History

2021-10-06 10:55:22 +02:00
#include "random.hpp"
sc::random sc::random::singleton {};
2021-10-06 11:28:24 +02:00
bool sc::random::boolean() {
2021-10-06 10:55:22 +02:00
std::uniform_int_distribution<int> dist {0, 1};
2021-10-06 11:28:24 +02:00
return dist(instance()._reng) == 1;
2021-10-06 10:55:22 +02:00
}
2021-10-06 11:28:24 +02:00
int sc::random::int_between(int from, int to) {
2021-10-06 10:55:22 +02:00
std::uniform_int_distribution<int> dist {from, to};
2021-10-06 11:28:24 +02:00
return dist(instance()._reng);
2021-10-06 10:55:22 +02:00
}
2021-10-06 11:28:24 +02:00
double sc::random::double01() {
2021-10-06 10:55:22 +02:00
std::uniform_real_distribution<double> dist {};
2021-10-06 11:28:24 +02:00
return dist(instance()._reng);
2021-10-06 10:55:22 +02:00
}
2021-10-06 11:28:24 +02:00
double sc::random::double_between(double from, double to) {
2021-10-06 10:55:22 +02:00
std::uniform_real_distribution<double> dist {from, to};
2021-10-06 11:28:24 +02:00
return dist(instance()._reng);
2021-10-06 10:55:22 +02:00
}