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

Name

Description

c

The container to sample from.

result

The output iterator receiving the sampled elements.

n

The number of elements to sample.

gen

The uniform random bit generator driving the sampling.

Created with MrDocs