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