Or login with:
#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 |
[first,last) - 1.#include <iostream> #include <vector> #include <algorithm> using namespace std; int main() { int a[] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10}; vector<int> v(a, a+10); cout <<"\nHere are the values in the vector:\n"; for (vector<int>::size_type i=0; i<v.size(); i++) cout <<v.at(i)<<" "; cout << "\nNow we randomize the order of the values."; random_shuffle(v.begin(), v.end()); cout <<"\nHere are the revised contents of the vector:\n"; for (vector<int>::size_type i=0; i<v.size(); i++) cout <<v.at(i)<<" "; return 0; }
You must login to leave a messge