Changed choice function to use std::vector
This commit is contained in:
parent
087e31219c
commit
d0cf4102d6
@ -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:
|
||||||
|
Loading…
x
Reference in New Issue
Block a user