Changed choice function to use std::vector

This commit is contained in:
Bob Polis 2021-10-06 11:08:46 +02:00
parent 087e31219c
commit d0cf4102d6

View File

@ -2,6 +2,7 @@
#define RANDOM_H_ #define RANDOM_H_
#include <random> #include <random>
#include <vector>
namespace sc { namespace sc {
@ -24,10 +25,10 @@ namespace sc {
double random_double(); double random_double();
double random_double(double from, double to); double random_double(double from, double to);
template <typename T, typename Iter> template <typename T>
T choice(Iter beg, Iter end) { static T choice(const std::vector<T>& vec) {
std::uniform_int_distribution<int> dist {0, end - beg - 1}; std::uniform_int_distribution<int> dist {0, vec.size() - 1};
return beg + dist(_reng); return vec[dist(instance()._reng)];
} }
private: private: