#include "base/random.hpp" #include #include namespace base { std::vector RandomSample(size_t n, size_t k, std::minstd_rand & rng) { std::vector result(std::min(k, n)); std::iota(result.begin(), result.end(), 0); for (size_t i = k; i < n; ++i) { size_t const j = rng() % (i + 1); if (j < k) result[j] = i; } return result; } } // base