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