I have an array of n integers. I need to shuffle the array in some random order multiple times during m iterations of the program.
I mean for each of m iterations, the array of n integers needs to be shuffled .
What I do is that I pass an input and an output array of n integers each with the input containing 1 to n and output contains same numbers but in shuffled order.
However the issue I am getting with my code is that consecutive shuffles collide and return same shuffled array .
like if its
1,54,7,11,13,.....
in 1st iteration then even in 2nd and 3rd iterations i get the same order ie
1,54,7,11,13,.....
1,54,7,11,13,.....
and again in 4th iteration a new order appears but repeats for next 2,3 iterations
23,1,4,6,76,11,......
23,1,4,6,76,11,......
whereas my requirement is that each time the shuffling should be unique. My shuffling function code is pasted below
void ShufflingUtility::randomShuffle(int inputArray[],int size,int returnArray[])
{
srand(time(0));
std::random_shuffle(&inputArray[0], &inputArray[size]);
for(int j=0;j<size;j++)
{
returnArray[j] = inputArray[j];
}
}
Any suggestion to resolve this duplication issue is welcome. Thanks in advance.