an example of using STL alg
random_shuffle
👍 g++ -std=c++11 random_shuffle.cpp
👍 ./a.out
3 1 4 1 5 9 2 6
5 6 1 1 4 2 3 9
1 4 2 9 3 5 1 6
👍 ./a.out
3 1 4 1 5 9 2 6
5 6 1 1 4 2 3 9
1 4 2 9 3 5 1 6
👍 cat random_shuffle.cpp
#include <iostream>
#include <vector>
using namespace std;
template<typename C>
void prt(C c) {
for(auto i=c.begin();i!=c.end();++i)
cout << *i << ' ';
cout << endl;
}
int main() {
vector<int> v{3,1,4,1,5,9,2,6};
prt(v);
random_shuffle(v.begin(), v.end());
prt(v);
random_shuffle(v.begin(), v.end());
prt(v);
}