random_shuffle

random_shuffle

template<class RanIt>
    void random_shuffle(RanIt first, RanIt last);
template<class RanIt, class Fun>
    void random_shuffle(RanIt first, RanIt last, Fun& f);

The first template function evaluates swap(*(first + N), *(first + M)) once for each N in the range [1, last - first), where M is a value from some uniform random distribution over the range [0, N). Thus, the function randomly shuffles the order of elements in the sequence.

The second template function behaves the same, except that M is (Dist)f((Dist)N), where Dist is the type iterator_traits::distance_type.

Sample programs: random_shuffle and random_shuffle (predicate version).