#include <iostream> #include <vector> #include <algorithm> using namespace std; class Print { public: void operator()(int i) { cout << i << endl; } }; int main() { srand(time(NULL)); vector<int> v; for(int i = 0; i < 10; i++) { v.push_back(i); } random_shuffle(v.begin(), v.end()); for_each(v.begin(), v.end(), Print()); return 0; }
注:使用时,记得加随机数种子