How can I pick multiple values randomly in any given integer range?
With std::sample(),
one possible implementation would be:
void Sample(
int first, int last, std::vector<int> *out, std::size_t n, std::mt19937 *g)
{
std::vector<int> in{};
for (int i = first; i < last; ++i)
{
in.emplace_back(i);
}
std::sample(in.begin(), in.end(), std::back_inserter(*out), n, *g);
}
But I'm hesitating because creating in vector seems redundant and impractical,
especially when first is 0 and last is very big number.
Is there any public implementation or library for this requirement? e.g.:
sample(int first, int last, ...)or,ranges::sample(int n, ...)