Skip to content

Commit 78e747b

Browse files
committed
Added an output file
1 parent 186aa7e commit 78e747b

File tree

1 file changed

+32
-17
lines changed

1 file changed

+32
-17
lines changed

shuffle.cc

Lines changed: 32 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -2,47 +2,62 @@
22
#include <algorithm>
33
#include <vector>
44
#include <cstdlib>
5-
#include <ctime>
5+
#include <ctime>
6+
#include <fstream>
67

78
using namespace std;
89

910
int NUM_SIZE=10;
1011

11-
int myrandom (int i) { return std::rand()%i;}
12+
int myrandom (int i)
13+
{
14+
return std::rand()%i;
15+
}
1216

1317
int main()
1418
{
1519
vector<int> r;
16-
int count=0;
20+
int count = 0;
21+
int filecount = 0;
1722
srand(time(0));
1823

19-
for(int i=0; i < NUM_SIZE; i++)
24+
ofstream myfile;
25+
myfile.open ("output.csv");
26+
myfile.open("output" << filecount << ".csv");
27+
28+
for(int i=0; i < NUM_SIZE; i++) //Added numbers to the vector
2029
{
2130
r.push_back(i);
2231
}
2332

24-
random_shuffle(r.begin(), r.end(), myrandom);
33+
random_shuffle(r.begin(), r.end(), myrandom); //Do the first shuffle
2534

2635
while (true)
2736
{
28-
if (is_sorted(r.begin(), r.end()))
29-
break;
30-
37+
if (is_sorted(r.begin(), r.end())) //Check to see if the vector is sorted
38+
break;
3139

32-
random_shuffle(r.begin(), r.end(), myrandom);
33-
34-
for (int i=0; i < NUM_SIZE; i++)
40+
random_shuffle(r.begin(), r.end(), myrandom); //Shuffle the vector
41+
42+
for (int i=0; i < NUM_SIZE; i++) //Add the vector contents into the csv
3543
{
36-
cout << r[i];
44+
myfile << r[i] << ",";
3745
}
38-
cout << endl;
3946

40-
count++;
41-
cout <<count <<endl;
47+
myfile << "\n";
4248

49+
if (count >= 995000) //If the file has more than 995000 line in it, Make a new file
50+
{
51+
count = 0;
52+
filecount++;
53+
myfile.close();
54+
myfile.open("output" << filecount << ".csv"); //Open the new file
55+
}
56+
count++;
4357
}
4458

45-
59+
60+
myfile.close();
4661
return 0;
47-
62+
4863
}

0 commit comments

Comments
 (0)