### Calculating the Value of Pi With a Geiger Counter

Can a Geiger counter do math? Indeed it can!
Well it can at least be used to generate a stream of random binary which can be utilized in a Monte-Carlo method to perform the computation.  This was motivated by a desire to build a hardware random number generator and verify that the numbers generated by the HRNG are sufficiently random to be used in computations and simulations.

All code for this project was written using Python and can be downloaded here:
https://github.com/pmt-hrng/Hardware-Random-Number-Generator
METHOD
The method is quite simple.  As the decay of a radioisotope is random in nature, they are a prime source of entropy which can be used to generate truly random numbers.  The hardware component is a Geiger Counter equipped with an Atmega328P, the same MCU on the Arduino Uno, which makes life easy.

The microcontroller was loaded with a small program which continuously output a stream of zeros and ones pending an interrupt routine initiated by the Geiger counter. The output pulse of the as SB-20 Geiger-Muller tube was fed to the interrupt pin of the Atmega328P MCU.   When the MCU detects the falling edge of an incoming pulse, an interrupt routine is triggered which outputs a one within the stream of zeros.  As the time when the radioisotope will decay cannot be pre-determined, a random stream of bits is generated.
To increase the collection rate, a thorium containing mineral was placed next to the GM tube.  This increased the count rate to roughly 9500cpm.
The random stream of bits is sent to a PC and read by PySerial for further processing.

De-Biasing
The random bit stream generated by this method is not uniform and thus a “Von-Numan” Filter must be employed to remove the bias.  Pairs of consecutive bits (00 and 11) are discarded.  Alternative bits (01 and 10) are recorded as ‘zero’ and a ‘one’ respectively.  This ensures a close to 50/50 split between the number of zeros and ones in the random bit stream.
Integer Conversion
Via python, a large text file of random binary was generated.  This random binary was then converted to 16bit integers and saved in another file for use in the Monte-Carlo Method to Approximate Pi.
Monte-Carlo Method
The Monte-Carlo method for approximating pi is quite simple. Inscribe a circle within a square.  Propagate this space with random points generated from the HRNG above.  Count the number of points which lie within the boundary of the circle and the total number of points and calculate the ratio.  Recall that the ratio of the area of a circle to that of a square is pi/4.
Thus Pi = 4*(#_points_within_circle/total_point).  70,000 numbers or 35,000 random points were plotted and approximated the value of Pi
How Well Did it work?
Actual Value of Pi:           3.14159
Calculated Value of Pi:    3.12793
My Geiger counter calculated the value of Pi to within 0.56%. This bodes well for the truly random nature of the numbers generated by this system.

From a more cosmic perspective the result is truly quite odd.  By monitoring a radioactive mineral I have essentially asked a rock to calculate value of pi for me.  I did not so much compute the value myself as I created a framework and let the universe fill in the requisite information for me.

Cryptographically Secure?
I am no expert, however the field of cryptography and other methods of random number generation are quite intriguing.  The next step will be to further test the binary stream generated from this device and put the data through a battery of statistical tests.  If anyone wants to chime in about radioisotope hardware random number generators I would love to hear it.

If you desire a gigabyte .txt file of de-biased binary generated from this device for whatever reason, send an email.

Links:

The awesome DIY and highly hack-able Geiger counter kit used:
https://sites.google.com/site/diygeigercounter/
Git Hub address with all the code used:
https://github.com/pmt-hrng/Monte-Carlo-Aprx.-of-Pi

Advertisements