In [2]:
%matplotlib inline
import matplotlib.pyplot as plt
import itertools
import functools
import operator

In [3]:
def prob_collision(n, s):
    probs = (e/k for e, k in zip(range(s, s-n, -1), itertools.cycle([s])))
    return 1 - functools.reduce(operator.mul, probs, 1)

In [13]:
x = range(2, 10000, 10)
plt.figure(figsize=(12, 8))
plt.style.use("ggplot")
plt.rcParams.update({'font.size': 16})
plt.ylabel('Probability of Collision')
plt.xlabel('Number of CualIDs')
plt.yscale('log')
plt.ylim([10e-8, .35])

for id_length, name in zip([4, 5, 6], ['Four', 'Five', 'Six']):
    plt.plot(x, [prob_collision(n, id_length**16) for n in x], linewidth=2, label='{0} Character IDs'.format(name))
    
plt.legend()
plt.savefig('figure2.pdf', dpi=300)