rndshuf2.cpp
rndshuf2.cpp
#include ‹stl.h›
#include ‹stdlib.h›
#include ‹iostream.h›
class MyRandomGenerator {
public:
nsigned long operator()(unsigned long n_);
};
unsigned long MyRandomGenerator::operator()(unsigned long n_) {
return rand() % n_;
}
int main() {
vector‹int› v1(10);
iota(v1.begin(), v1.end(), 0);
ostream_iterator ‹int› iter(cout, " ");
copy(v1.begin(), v1.end(), iter);
cout ‹‹ endl;
MyRandomGenerator r;
for (int i = 0; i ‹ 3; i++) {
random_shuffle(v1.begin(), v1.end(), r);
copy(v1.begin(), v1.end(), iter);
cout ‹‹ endl;
}
return 0;
}