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 ([input.iterators]).
SampleIterator shall satisfy the requirements of an output iterator ([output.iterators]).
SampleIterator shall satisfy the additional requirements of a random access iterator ([random.access.iterators]) unless PopulationIterator satisfies the additional requirements of a forward iterator ([forward.iterators]).
PopulationIterator's value type shall be writable ([iterator.requirements.general]) to out.
Distance shall be an integer type.
remove_reference_t<UniformRandomBitGenerator> shall meet the requirements of a uniform random bit generator type ([rand.req.urng]) 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 ]
Returns: The end of the resulting sample range.
Complexity: Ο(last - first).