25 Algorithms library [algorithms]

25.7 Mutating sequence operations [alg.modifying.operations]

25.7.13 Shuffle [alg.random.shuffle]

template<class RandomAccessIterator, class UniformRandomBitGenerator> void shuffle(RandomAccessIterator first, RandomAccessIterator last, UniformRandomBitGenerator&& g); template<random_­access_­iterator I, sentinel_­for<I> S, class Gen> requires permutable<I> && uniform_­random_­bit_­generator<remove_reference_t<Gen>> I ranges::shuffle(I first, S last, Gen&& g); template<random_­access_­range R, class Gen> requires permutable<iterator_t<R>> && uniform_­random_­bit_­generator<remove_reference_t<Gen>> borrowed_iterator_t<R> ranges::shuffle(R&& r, Gen&& g);
Preconditions: For the overload in namespace std:
Effects: Permutes the elements in the range [first, last) such that each possible permutation of those elements has equal probability of appearance.
Returns: last for the overloads in namespace ranges.
Complexity: Exactly (last - first) - 1 swaps.
Remarks: To the extent that the implementation of this function makes use of random numbers, the object referenced by g shall serve as the implementation's source of randomness.