Let's say I have the following matrix
arr1[0,$i] = 0,0,0,0,1,1,1,1,1,2,2,2,2,2,2,3,3,3,3,3
arr1[1,$i] = 0,0,0,1,1,1,1,1,2,2,2,3,3,3,4,4,4,4,5,5
arr1[2,$i] = 0,0,0,0,0,0,0,1,1,1,1,1,2,2,2,2,2,2,2,2
arr1[3,$i] = 0,0,1,1,2,2,3,3,3,4,4,4,5,5,5,6,6,6,6,6
I want to obtain a matrix that has the same number of rows and columns as the original one but with randomized elements that fulfils the following 2 conditions:
- Each row of arr2 has to heave the same elements as arr1 but in a random order.
- All columns of arr2 should be unique.
Example:
arr2[0,$i] = 0,1,2,3,0,1,2,3,0,1,2,3,0,1,2,3,1,2,3,2
arr2[1,$i] = 0,1,2,3,4,5,0,1,2,3,4,5,0,1,2,3,4,1,4,1
arr2[2,$i] = 0,1,2,0,1,2,0,1,2,0,1,2,0,1,2,0,2,0,2,2
arr2[3,$i] = 0,1,2,3,4,5,6,0,1,2,3,4,5,6,3,4,5,6,6,6
All I have managed until now was to grow arr1 2 or 3 times, randomize each line, start writing to arr2 column by column and check if the column is unique, if not, just go to the next column in the grown array until I have enough columns to fill arr2. This is not a solution since it does not fulfill condition 1, exactly. It is somehow close but not perfect.
If it is not possible to fulfill condition 2, an error should be displayed.
P.S.: This is an oversimplification of the actual script, putting it all here would just create confusion. If I can figure a way of doing this with your help, I can adapt it to my script. The values in arr2 are actually used as inputs for another array
arr3[$j,arr[0,$i]]