Hi there,
I am working with a 2D array, my c++ program reads input from an external file and stores it into a 2D array. Say, for example, this is my input file:
9 5 6 2
4 1 0 8
6 7 3 5
2 9 5 8
My problem is I want to randomly shuffle only the rows so I get row 1 [9 5 6 2] somewhere in maybe row 3 and row 3 is found somewhere in row 2 and so forth, where my columns are kept intact. Most searches online give me how to shuffle the elements in a row - random shuffling of rows AND columns. However, below is what I've done so far to get the values that were repeating themselves but it was obvious from my output that shuffling of columns were done as well-which is what I do NOT want.
What I want to know is if I'm on the right track, then what am I doing wrong? Or where am I going wrong?
Here's what my shuffling code looks like given my variables and array were defined and initialized and I've read from input file:
int r;
int t;
for(int k=0;k<4;k++){
for(int m=0;m<4;m++){
r=rand()%4;
t=rri_val[k][m];
rri_val[k][m]=rri_val[r][m];
rri_val[r][m]=t;
cout<<rri_val[k][m]<<" ";
}
}
I need clarifications asap... Thanks,
Lee