编辑代码

#include <iostream>
using namespace std;
#include <vector>
#include <algorithm>
#include <ctime>

class myPrint {
public:
	void operator()(int val) {
        cout << val << " ";
    }
};

void test01() {
    vector<int> v;
	for(int i = 0 ; i < 10;i++) {
		v.push_back(i);
	}
    cout << "before random: " << endl;
    for_each (v.begin(), v.end(), myPrint());
    cout << endl;

    random_shuffle(v.begin(), v.end());
    cout << "after random: " << endl;
    for_each (v.begin(), v.end(), myPrint());
    cout << endl;
}

int main() {
    srand((unsigned int)time(NULL));
    test01();
	return 0;
}