random_shuffle
Brings the elements into a random order
Definition
The random_shuffle() algorithm is defined in the standard header <algorithm> and in the nonstandard backward-compatibility header <algo.h>.
Interface
#include <algorithm>
template < class RandomAccessIterator >
void random_shuffle(
RandomAccessIterator first,
RandomAccessIterator last
);
template < class RandomAccessIterator, class RandomNumberGenerator >
void random_shuffle(
RandomAccessIterator first,
RandomAccessIterator last,
RandomNumberGenerator& rand
);Parameters:
| Parameter | Description |
| first | A random-access iterator addressing the position of the first element in the range to be rearranged |
| last | A random-access iterator addressing the position one past the final element in the range to be rearranged |
| rand | A special function object called a random number generator |
Description
Random_shuffle function reorders the elements of a range by putting them at random places.
The first version uses an internal random number generator, and the second uses a Random Number Generator, a special kind of function object, that is explicitly passed as an argument.
Return Value
None.
Complexity
The complexity is linear; performs as many calls to swap as the length of the range [first,last) - 1.
CodeCogs®