scrivener writes:
> Let me simplify to the example that actually got the discussion of
> this going with a friend:
>
> A random number generator produces numbers from 1 to 10. In five
> runs it produces numbers in the range from 1 to 2, 1 to 3, 1 to 4, 1
> to 5, and 1 to 6. What is the probability of this happening?
>
> Well, in sequence, the probability is .2 x .3 x .4 x .5 x .6 =0.0072.
>
> But if the numbers can be produced in any sequence, what is the
> probability? That is, what is the probability that in the next five
> runs the generator will produce five numbers no larger than 2, 3, 4,
> 5, and 6 but in any sequence?
A brute force computation says that 4802 sequences out of the 100000
possible satisfy the condition.
Python 3 code, which lists the ordered sequences, then builds the set
(removing duplicates) of their permutations, prints the sizes of the
two sets, and as a sanity check also prints a sample of the sequences:
from itertools import product, permutations, chain
from functools import partial
import random
ospool = tuple(product(*map(partial(range, 1), range(3, 8))))
uspool = set(chain.from_iterable(map(permutations, ospool)))
print('# ordered:', len(ospool), '=', 2 * 3 * 4 * 5 * 6)
print('#shuffled:', len(uspool))
print(' ordered:', random.sample(ospool, 3))
print(' ordered:', random.sample(ospool, 3))
print(' ordered:', random.sample(ospool, 3))
print('shuffled:', random.sample(uspool, 3))
print('shuffled:', random.sample(uspool, 3))
print('shuffled:', random.sample(uspool, 3))
Sample output:
# ordered: 720 = 720
#shuffled: 4802
ordered: [(2, 1, 1, 3, 1), (2, 1, 2, 4, 2), (2, 3, 1, 3, 3)]
ordered: [(1, 3, 1, 4, 6), (2, 1, 1, 4, 1), (1, 2, 3, 1, 3)]
ordered: [(2, 3, 4, 1, 2), (1, 2, 1, 2, 1), (2, 3, 4, 3, 5)]
shuffled: [(3, 3, 1, 2, 1), (3, 3, 2, 4, 1), (4, 3, 6, 2, 2)]
shuffled: [(6, 2, 2, 4, 5), (4, 1, 2, 5, 3), (3, 5, 1, 2, 2)]
shuffled: [(1, 5, 3, 5, 4), (1, 3, 4, 3, 5), (5, 3, 2, 3, 5)]