absl::c_sample

Container-based version of the <algorithm> std::sample() function to randomly sample elements from the container without replacement using a gen() uniform random number generator and write them to an iterator range.

Synopsis

Declared in <absl/algorithm/container.h>

template<
    typename C,
    typename OutputIterator,
    typename Distance,
    typename UniformRandomBitGenerator>
OutputIterator
c_sample(
    C const& c,
    OutputIterator result,
    Distance n,
    UniformRandomBitGenerator&& gen);

Return Value

An iterator to the end of the written range in the output.

Parameters

NameDescription
cThe container to sample from.
resultThe output iterator receiving the sampled elements.
nThe number of elements to sample.
genThe uniform random bit generator driving the sampling.