I analysed the distribution of numbers in the first million digits of π. You can download them for example from PILookup (direct download link) if you want to follow along. Don’t forget to extract the zip file!

A simple Python script is enough to read the file and count the occurrences of each digit. We can use a dictionary to store the counts, which is initialised with 0 for each digit.

with open("1-1000000.txt") as f:
    pi = f.read()
    count = dict((str(i), 0) for i in range(10))
    for digit in pi:
        count[digit] += 1
    print(count)

Et voilà, the result:

{'0': 99959, '1': 99758, '2': 100026, '3': 100229, '4': 100230, '5': 100359, '6': 99548, '7': 99800, '8': 99985, '9': 100106}

This is only counting digits after the decimal point, to include the first 3 increase the count for 3 and take away the 1 at the millionth place.

If you want to see it as a nice graph, add the following code:

import matplotlib.pyplot as plt

plt.bar(count.keys(), count.values())
plt.show()

million-digits-of-pi.svg

The distribution is pretty even, so you might consider using Pi as a (pseudo) random number generator. It would be pretty good on its own (study 1, study 2, 10 million digits), but randomness is usually meant as unguessable numbers (at least without significant effort). As soon as someone recognizes the sequence, the surprise is gone and for example getting “random” rewards in a game becomes predictable and boring. On the other hand, most people only know the first few digits of Pi, so if you start with a large enough offset, you should be fine.

Tags: ,

Categories:

Updated:

Comments