I am trying to generate multiple files (say 100) of shuffled integers for a particular range (for eg: 1000, 10000 etc). This is the code I have tried so far
std::srand ( unsigned ( std::time(0) ) );
std::vector<int> myvector2;
// For creating 10 different shuffled files
for(int j=0;j<10;j++){
// set some values:
for (int i=1; i<=10000; ++i) myvector2.push_back(i);
std::random_shuffle ( myvector2.begin(), myvector2.end() );
std::random_shuffle ( myvector2.begin(), myvector2.end(), myrandom);
std::cout << "Data Shuffled:";
// put content in out file
std::ofstream f2("out.txt");
for (std::vector<int>::iterator it=myvector2.begin(); it!=myvector2.end(); ++it)
f2<< *it <<'\n';
}
return 0;
The file 'out.txt' gets overwritten and I end up with just one file. How can I create multiple files which have different set of shuffled integers in each file?
Thank You
Aucun commentaire:
Enregistrer un commentaire