- <span style="font-size:14px;">#include <iostream>
- #include <vector>
- #include <iterator>
- #include <algorithm>
- using namespace std;
- int main (int argc, char *argv[])
- {
- int n = 10;
- vector<int> v;
- //append integers 0 to n-1 to v
- for (int i = 0; i < n; ++i) {
- v.push_back(i);
- }
- //random shuffle the values of v
- random_shuffle (v.begin(), v.end());
- //print all values of v to screen
- copy (v.begin(), v.end(), ostream_iterator<int> (cout, " "));
- return 0;
- }</span>
- 转自 http://blog.csdn.net/cywosp/article/details/7317977