Files
cppdraft_translate/cppdraft/alg/random/shuffle.md
2025-10-25 03:02:53 +03:00

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); `

1

#

Preconditions: For the overload in namespace std:

2

#

Effects: Permutes the elements in the range [first, last) such that each possible permutation of those elements has equal probability of appearance.

3

#

Returns: last for the overloads in namespace ranges.

4

#

Complexity: Exactly (last - first) - 1 swaps.

5

#

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.