Rogue Wave banner
Previous fileTop of documentContentsIndexNext file

random_shuffle


Algorithm

Summary

Randomly shuffles elements of a collection.

Data Type and Member Function Indexes
(exclusive of constructors and destructors)

None

Synopsis

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

Description

The random_shuffle algorithm shuffles the elements in the range [first, last) with uniform distribution. random_shuffle can take a particular random number generating function object rand (where rand takes a positive argument n of distance type of the RandomAccessIterator) and returns a randomly chosen value between 0 and n - 1.

Complexity

In the random_shuffle algorithm, (last - first) -1 swaps are done.

Example

Program Output

Warnings

If your compiler does not support default template parameters, you always need to supply the Allocator template argument. For instance, you need to write:

vector<int, allocator<int> >

instead of:

vector<int>

If your compiler does not support namespaces, then you do not need the using declaration for std.



Previous fileTop of documentContentsIndexNext file
©Copyright 1998, Rogue Wave Software, Inc.
Send mail to report errors or comment on the documentation.
OEM Release, June 1998