Problem Statement
I need to simulate the process of 100 Prisoner Problem, in which each drawer of a cupboard of size 100 contains a unique number from 0 to 99. I initialze the number of drawers as follows:
def arrange_event(n_prisoners=100):
if (n_prisoners % 2) != 0 or n_prisoners <=0:
raise ValueError("Number of prisoners must be a postive and even number.")
drawer = list(range(n_prisoners))
random.shuffle(drawer)
return drawer
But I doubt that this implementation (e.g.shuffling from a specific list) will introduce bias to some specific patterns during sampling. A correct implemenation of list initialzation is needed. Any explanation of the bias (if exists) introduced in this implementation will be helpful as well.
Note
I'm not simply asking how to make each initiazation random, the key is that the probabilty of each permutation should be equal in the expcted implemetation, which is completely different from this question.
Here's what I found in the official document, which suggests that the probability distrbution over permutations are biased in my implemetation using random.shuffle()
.
random.shuffle(x[, random])
Shuffle the sequence x in place. The optional argument random is a 0-argument function returning a random float in [0.0, 1.0); by default, this is the function random().
Note that for even rather small len(x), the total number of permutations of x is larger than the period of most random number generators; this implies that most permutations of a long sequence can never be generated.