| 181 | |
| 182 | template <typename Container, typename Generator> |
| 183 | typename Container::const_reference pickRandom(Generator &g, const Container &c) |
| 184 | { |
| 185 | // we can't do index lookups in a list, so we just have to iterate N times |
| 186 | if (c.size() == 1) |
| 187 | { |
| 188 | return *begin(c); |
| 189 | } |
| 190 | else if (c.empty()) |
| 191 | { |
| 192 | throw std::runtime_error("Trying to randomize within empty container"); |
| 193 | } |
| 194 | return *std::next(begin(c), randBoundsExclusive(g, (unsigned)0, (unsigned)c.size())); |
| 195 | } |
| 196 | |
| 197 | } // namespace OpenApoc |
no test coverage detected