From a0f852d4196744627f92f9a3a6039c22d1561b48 Mon Sep 17 00:00:00 2001 From: Bob Polis Date: Thu, 7 Oct 2021 15:59:08 +0200 Subject: [PATCH] Added iterator-based choice function --- src/random.hpp | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/random.hpp b/src/random.hpp index 15f4a69..a47181c 100644 --- a/src/random.hpp +++ b/src/random.hpp @@ -31,6 +31,12 @@ namespace sc { return vec[dist(instance()._reng)]; } + template + T choice(Iter from, Iter to) { + std::uniform_int_distribution dist {0, static_cast(to - from) - 1}; + return *(from + dist(instance()._reng)); + } + private: static random singleton;