diff --git a/libs/random/include/psemek/random/uniform.hpp b/libs/random/include/psemek/random/uniform.hpp index b6ebc42e..c7608945 100644 --- a/libs/random/include/psemek/random/uniform.hpp +++ b/libs/random/include/psemek/random/uniform.hpp @@ -7,6 +7,7 @@ #include #include +#include namespace psemek::random { @@ -47,4 +48,12 @@ namespace psemek::random return uniform(rng, T{0}, T{2 * geom::pi}); } + template + auto & uniform_from(RNG && rng, Container & container) + { + if (container.empty()) + throw std::runtime_error("cannot sample from empty container"); + return container[uniform(rng, 0, container.size() - 1)]; + } + }