Suppose I have a numpy shuffled array:
a = np.array([1,2,3,4,5,6]*6)
np.random.shuffle(a)
How can I guarantee that every element in a shuffled array follows every other element an equal number of times?
For example, I want to make sure that number 1 follows number 2 in the array as many times as it follows number 4. Similarly, for all other numbers
We can assume that the list is round for this problem, i.e. the first element follows the last
Normally I would post the code of what I tried, but I don't understand when it comes to this.
The most inefficient way I can think of is to write a function that counts how many times a number follows another number, and then check that all the counts are equal. If not, rearrange.
But this does not guarantee that I have ever completed a list that meets the criteria for equal distribution.
Simon source
share