25 Algorithms library [algorithms]

25.6 Mutating sequence operations [alg.modifying.operations]

25.6.12 Sample [alg.random.sample]

template<class PopulationIterator, class SampleIterator, class Distance, class UniformRandomBitGenerator> SampleIterator sample(PopulationIterator first, PopulationIterator last, SampleIterator out, Distance n, UniformRandomBitGenerator&& g);
Mandates: Distance is an integer type.
*first is writable ([iterator.requirements.general]) to out.
Effects: Copies elements (the sample) from [first, last) (the population) to out such that each possible sample has equal probability of appearance.
Algorithms that obtain such effects include selection sampling and reservoir sampling.
— end note
Returns: The end of the resulting sample range.
Complexity: .
  • Stable if and only if PopulationIterator meets the Cpp17ForwardIterator requirements.
  • To the extent that the implementation of this function makes use of random numbers, the object g shall serve as the implementation's source of randomness.