Added iterator-based choice function

This commit is contained in:
Bob Polis 2021-10-07 15:59:08 +02:00
parent a6accef426
commit a0f852d419

View File

@ -31,6 +31,12 @@ namespace sc {
return vec[dist(instance()._reng)]; return vec[dist(instance()._reng)];
} }
template <typename T, typename Iter>
T choice(Iter from, Iter to) {
std::uniform_int_distribution<int> dist {0, static_cast<int>(to - from) - 1};
return *(from + dist(instance()._reng));
}
private: private:
static random singleton; static random singleton;