Max of two random values distribution

34 Views Asked by At

Consider code like this. Briefly. We throw two dice NUMBER_OF_RUNS times. Each dice has BIN_COUNTS faces. We pick the larger value. Then we plot M vs the number of times we see M as the largest value in the throw.

Apparently, the distribution is linear or near linear. How is it possible?

from random import randint
import numpy as np

BIN_COUNTS = 5000
NUMBER_OF_RUNS = 50000000

bins = np.zeros(BIN_COUNTS)
for i in range(0, NUMBER_OF_RUNS):
    bins[max(randint(0, BIN_COUNTS-1), randint(0, BIN_COUNTS-1))] += 1

for j in range(BIN_COUNTS):
    print(f'{j}\t{bins[j]}')
1

There are 1 best solutions below

0
On BEST ANSWER

For an ordinary die with $6$ sides: The probability that both rolls are $≤i$ is $P(M≤i)=P_i=\left(\frac i6\right)^2$ so the probability that the maximum is exactly $i$ is $$P(M=i)=P_i-P_{i-1}=\frac i{18}-\frac 1{36}$$ which is linear in $i$.

Similarly, if the die has $S$ sides we see that $$P(M=i)=\left(\frac iS\right)^2-\left(\frac {i-1}S\right)^2=\frac {2i-1}{S^2}$$.