random_sample

C++ Reference

random_sample
Syntax:
  #include <algorithm>
  iterator random_sample( iterator start1, iterator end1, iterator start2, iterator end2 );
  iterator random_sample( iterator start1, iterator end1, iterator start2, iterator end2, RandomNumberGenerator& rnd );

The random_sample() algorithm randomly copies elements from [start1,end1) to [start2,end2). Elements are chosen with uniform probability and elements from the input range will appear at most once in the output range.

If a random number generator function object rnd is supplied, then it will be used instead of an internal random number generator.

The return value of random_sample() is an iterator to the end of the output range.

random_sample() runs in linear time.

Related topics: