## Decimal Expansion of Pi: Interesting Observations, Part I

Let’s try to read through decimal expansion of pi until every digit from 0 to 9 is found at least once, and note the count of digits we’ve read up to that point (call that count completion run). The first such position for decimal expansion of pi (actually including the leading 3) is 33. That is, if I start reading the digits 3, 1, 4, 1 … it will take me 33 digits before all digits between 0 and 9 are read at least once. In parallel, let’s do the same for completely random sequence of numbers. Once we reach the point when all the digits have been encountered, we reset the length. Thus between any two sequences of digits, each digit between 0 to 9, there is a sequence of completion runs. Again, if we read pi from 3, 1, 4, 1, 5 … (until 1,000,000 have been read) we get a sequence of completion runs which have following lengths: 33, 18, 19, 27, 15 etc. If we have first 1,000,000 digits of pi written out to pi.txt, the following C++ code would accomplish the task.

```
#include <iostream>
#include <fstream>
#include <cstdlib>
#include <ctime>
using namespace std;
int main(){
ifstream inFile ("pi.txt");
ofstream outFile ("out.txt");
char c;
int i =0;
int a[10];
int g = 0;
srand(time(NULL));
for (i = 0; i < 10; i++) a[i] = 0;
while(!inFile.eof() ){
inFile.read( &c, 1 );
int j = c - 48;
// j = rand() %10; // comment/uncomment to simulate truly random sequence
a[j]++;
int k = 0;
for (i = 0; i < 10; i++) if (a[i] == 0) k = 1;
if (k) {
g++;
} else {
//cout << g + 1<< ' ';
outFile << g + 1 << endl;
g = 0;
for (i = 0; i < 10; i++) a[i]=0;
}
}
return(0);
}
```

What does the data show? Well, it’s interesting. Assuming random number generator employed in the code above produces true random sequence, it seems that maximal length of completion runs in the first million digits of pi is larger than that in the control random sequence. The table below shows counts of completion runs for pi and control random sequence. Every completion run length from pi has corresponding value for the control. For example, in my data, 33 (the length of first completion run on pi) is coupled with 15 (the length of first completion run from control sequence). Reading the table below, it follows that first million digits of pi contains a completion run with over 130 digits (it’s a 157 to be exact) and there is no such completion run observed for the control sequence. In fact, there is also a completion run of length 126 (between 120 and 130) and there is no such run observed in the first million ‘truly’ random digits.

Do you feel thrilled? Do we see a glimpse of ’empirical’ evidence that decimal expansion of pi is not truly random? Or do we see manifestation of imperfections in random number generators?