How do I change the repeated numbers in a list randomly such that the numbers are no longer repetitive?
I have my list to be A={{3, 1}, {4, 1, 2}, {1, 4, 5}}
. Here there are three 1's and and two 4's. I want one of 1's in the list to remain as 1 and the others to be changed into 2 and 3. The other numbers will change as well depending on the number smaller than it .
Example of outputs are A = {{5, 1}, {6, 2, 4}, {3, 7, 8}}
or A = {{5, 3}, {6, 1, 4}, {2, 7, 8}}
or A = {{5, 3}, {7, 2, 4}, {1, 6, 8}}
and so on.
Right now the coding that I have is TakeList[Ordering@Ordering@Flatten@A, Length /@ A]
(from this related Q/A) and the output for this is {{5, 1}, {6, 2, 4}, {3, 8, 7}}
, but this coding chooses to remain the first repeated number and changes the others. Can I know if there is a way to change this so that it randomly remains one of the other repeated numbers and not only the first one?
order1=RandomSample@Range@Length@A
to get a random order andA[[order1]]
to reorder your input list andresult[[Ordering@order1]]
to reorder your result. $\endgroup$