template<class PopulationIterator, class SampleIterator,
class Distance, class UniformRandomBitGenerator>
SampleIterator sample(PopulationIterator first, PopulationIterator last,
SampleIterator out, Distance n,
UniformRandomBitGenerator&& g);
Requires:
PopulationIterator shall satisfy the requirements of an input iterator.
SampleIterator shall satisfy the requirements of an output iterator.
SampleIterator shall satisfy the additional requirements of a random access iterator unless PopulationIterator satisfies the additional requirements of a forward iterator.
PopulationIterator's value type shall be writable to out.
Distance shall be an integer type.
remove_reference_t<UniformRandomBitGenerator> shall meet the requirements of a uniform random bit generator type whose return type is convertible to Distance.
out shall not be in the range [first, last).
Effects: Copies min(last - first, n) elements (the sample) from [first, last) (the population) to out such that each possible sample has equal probability of appearance. [ Note: Algorithms that obtain such effects include selection sampling and reservoir sampling. — end note ]