From d0cf4102d6b8175d623011a7ce3ff617b3725a55 Mon Sep 17 00:00:00 2001 From: Bob Polis Date: Wed, 6 Oct 2021 11:08:46 +0200 Subject: [PATCH] Changed choice function to use std::vector --- src/random.hpp | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/src/random.hpp b/src/random.hpp index aada12e..a040802 100644 --- a/src/random.hpp +++ b/src/random.hpp @@ -2,6 +2,7 @@ #define RANDOM_H_ #include +#include namespace sc { @@ -24,10 +25,10 @@ namespace sc { double random_double(); double random_double(double from, double to); - template - T choice(Iter beg, Iter end) { - std::uniform_int_distribution dist {0, end - beg - 1}; - return beg + dist(_reng); + template + static T choice(const std::vector& vec) { + std::uniform_int_distribution dist {0, vec.size() - 1}; + return vec[dist(instance()._reng)]; } private: