共用方式為


std::shuffle

Shuffles (rearranges) elements for a given range by using a random number generator.

template<class RandomAccessIterator, class UniformRandomNumberGenerator>
void shuffle(RandomAccessIterator first,
    RandomAccessIterator last,
    UniformRandomNumberGenerator&& gen);

Parameters

  • first
    An iterator to the first element in the range to be shuffled, inclusive. Must meet the requirements of RandomAccessIterator and ValueSwappable.

  • last
    An iterator to the last element in the range to be shuffled, exclusive. Must meet the requirements of RandomAccessIterator and ValueSwappable.

  • gen
    The random number generator that the shuffle() function will use for the operation. Must meet the requirements of a UniformRandomNumberGenerator.

Remarks

For more information, and a code sample that uses shuffle(), see <random>.

Requirements

Header: <algorithm>

Namespace: std

See Also

Reference

<algorithm>

Standard Template Library