1 | #pragma once
|
2 |
|
3 | #include <random>
|
4 | #include <iterator>
|
5 |
|
6 | // thanks to https://stackoverflow.com/a/16421677
|
7 |
|
8 | template<typename Iter, typename RandomGenerator>
|
9 | Iter select_randomly(Iter start, Iter end, RandomGenerator& g) {
|
10 | std::uniform_int_distribution<> dis(0, std::distance(start, end) - 1);
|
11 | std::advance(start, dis(g));
|
12 | return start;
|
13 | }
|
14 |
|
15 | template<typename Iter>
|
16 | Iter select_randomly(Iter start, Iter end) {
|
17 | static std::random_device rd;
|
18 | static std::mt19937 gen(rd());
|
19 | return select_randomly(start, end, gen);
|
20 | }
|