<jupyter_start><jupyter_text>Computing the distribution of the difference of two discrete uniform variables<jupyter_code>import matplotlib.pyplot as plt

# Plots the distribution of the difference of two discrete
# uniform RVs on the range 0...max
max = 255;
freq = {}

for i in range(0, max+1):
    for j in range(0, max+1):
        diff = i - j;
        freq[diff] = freq.get(diff, 0)+1;

normalized_freq = [x / (max**2) for x in freq.values()]        
        
# The plot
fig, ax = plt.subplots()
ax.plot(list(freq.keys()), normalized_freq)
ax.set(xlabel='n', ylabel='Pr(n)', title='Distribution of the difference of two uniform RVs')
ax.grid()
plt.show()<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.13226744186046513, 'fraction_numerical': 0.015988372093023256, 'mean_word_length': 3.9214285714285713, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '1', 'dir': 'jupyter-structured-clean-dedup', 'id': '614460', 'license': 'CC0-1.0', 'n_tokens_mistral': 247, 'n_tokens_neox': 238, 'n_words': 74, 'path': 'Difference of uniform.ipynb', 'repo_name': 'mfaella/ProbGameDesign', 'size': '688'}