3.3 KiB
[alg.random.shuffle]
26 Algorithms library [algorithms]
26.7 Mutating sequence operations [alg.modifying.operations]
26.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 S, class Gen> requires permutable && uniform_random_bit_generator<remove_reference_t> I ranges::shuffle(I first, S last, Gen&& g); template<random_access_range R, class Gen> requires permutable<iterator_t> && uniform_random_bit_generator<remove_reference_t> borrowed_iterator_t ranges::shuffle(R&& r, Gen&& g); `
Preconditions: For the overload in namespace std:
-
RandomAccessIterator meets the Cpp17ValueSwappable requirements ([swappable.requirements]).
-
The type remove_reference_t meets the uniform random bit generator ([rand.req.urng]) requirements.
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.