<
Previous mounth
09/10/2024
>
Next mounth
SMTWFTS
37
08
08
09
09
10
10
11121314
3815161718192021
3922232425262728
4029300102030405
4106070809101112

## Hot Projects

DIY Food Hacking

Open Solar Power

#### picoReflow

DIY Reflow Soldering

#### PiGI

RasPi Geiger Counter

Wideband Antenna

Map everything!

# Generating Entropy From Radioactive Decay With PiGI

Continuing on the final aspect of JamesT's very nice exploration of PiGI, we want to further examine the possibilities to create randomness from the output of a Geiger-counter. Of course we are using a PiGI as testbed for our experiments.

True randomness, in the sense of “provably unpredictable” is not easily available on a computer. Good arguments can be made that the available sources of entropy like clock jitter, floating analog inputs, network traffic etc, combined with the algorithmic magic of /dev/random and /dev/urandom are more than adequate for all non-cryptographic purposes, and probably unpredictable enough to safely use them in cryptography without worrying to much.

But paranoia and cryptography run hand in hand and using radioactive decay as source of entropy is an interesting application of physics to provide access to the elusive “true” randomness on a computer.

While the half-life gives the duration after which a particle has decayed with a probability of 50%, the exact moment of decay can not be predicted in any way. So a sample of radioactive material creates a stream of events in a Geiger-counter, which, due to the enormous amounts of atoms even in the tiniest sample, averages to a steady rate, but the specific event times (or delays between events) are unpredictable.

In the most fundamental form, our task is to produce a stream of equally probable 0's and 1's. To do this, we compare the last two delays between measured events. If one is longer than the other, the next bit is a 0 and if it is shorter it is a 1.

Radioactivity-based random number generators (RNGs) are not a new idea. The Hotbits project is active since 1996 and provides a nice explanation of the theory and setup.

Ionizing smoke detectors are a common source of the required radioactive sample, as they contain a small sample of Americium 241. Dan Veeneman shows how to disassemble such a smoke detector, and Jared Bouck explores how to visualize the alpha radiation with a webcam, similar to a Scintillator (and also uses the resulting data to generate randomness).

Random.org provides some excellent general introduction to randomness and explains the difference between true random number generators (TRNG) and pseudo random number generators (PRNG). A deeper coverage of the subject is provided by a project report by Markus Rohe: RANDy - A True-Random Generator Based On Radioactive Decay

## Implementation

### Hardware

We use a Raspberry Pi running Raspbian with a prototype PiGI-module and a LN712 Geiger-Müller-tube as hardware for our experiment.

An Americium 241 sample from an ionizing smoke detector is used as source of radioactivity. It has a stated activity of 1 Microcurie which equates about 37000 decays per second (Bequerel).

### Geigercounter Interface

We start with a minimal counter implementation in python. Every event in in the tube results in a falling edge on a certain GPIO input on the Pi. The class `GeigerCounter` sets up the GPIO if it is available or starts a thread which simulates the ticks if not. It also defines a function `tick` which is called for every event, simulted or real. For now it increments the `tick_counter` and prints the current value.

#### geiger.py

```

#!/usr/bin/env python
#minimal geigercounter

import time
import threading
import random

try:
import RPi.GPIO as GPIO
geiger_simulate = False
except ImportError:
print "Simulating"
geiger_simulate = True

GPIO_PIGI = 4
SIM_PER_SEC = 100

class GeigerCounter():
def __init__(self):
self.tick_counter = 0

if geiger_simulate:
self.simulator = threading.Thread(target=self.simulate_ticking)
self.simulator.daemon = True
self.simulator.start()
else:
GPIO.setmode(GPIO.BCM)
GPIO.setup(GPIO_PIGI,GPIO.IN)
GPIO.add_event_detect(GPIO_PIGI,GPIO.FALLING)
GPIO.add_event_callback(GPIO_PIGI,self.tick)

def simulate_ticking(self):
while True:
time.sleep(random.random()/(2*SIM_PER_SEC))
self.tick()

def tick (self,pin=0):
self.tick_counter += 1
print "Ticks: %d"%self.tick_counter

if __name__ == "__main__":
gc = GeigerCounter()
while True:
time.sleep(1)
```

Running this program, we register a background radiation event every few seconds with the sample removed from the tube and a torrent of events when we bring it closer, peaking at about 2500 ticks per second.

Although this is less then 10% of the expected 37000 Bequerel of the sample, this value seems plausible because the sample radiates in all directions and the tube only detects events in one direction. Imagining the window of the tube as one wall of a cube around the sample, we see that we can detect at most 1/6 of all decays.

### Entropy Generation

In order to generate randomness, we import the basic `GeigerCounter` class from geiger.py and extend it to a new class `EntropyGeigerCounter`. Every even and odd tick, we set a marker, and every even tick we use these markers to compare the length of the last two delays between ticks. The result of this comparison is toggled every time to compensate potential bias. So we get one bit of randomness for every two ticks. These bits are appended to a bit-string which is periodically consumed into bytes which are written to file.

#### entropygeiger.py

```#!/usr/bin/env python
#entropy generating geigercounter

import geiger
import time
import datetime

OUT_FILE = "entropy.bin"

class EntropyGeigerCounter(geiger.GeigerCounter):
def __init__(self):
#setup vars for randomness production
self.toggle = False
self.t0 = self.t1 = self.t2 = datetime.datetime.now()
self.bitstring = ""

#call __init__ of superclass
geiger.GeigerCounter.__init__(self)

def tick (self,pin=0):
# This works like this:
# time:   |------------|-------------|-----------|-----------|
# tick 0: t0
# tick 1: t0           t1
# tick 2: t2           t1            t0
#                d0            d1
# tick 3: t2                         t0          t1
# tick 4:                            t2          t1          t0
#                                          dO          d1

self.tick_counter += 1
if (self.tick_counter % 2) == 0:
self.t2 = self.t0
self.t0 = datetime.datetime.now()
d0 = self.t1 - self.t2
d1 = self.t0 - self.t1

if d0 > d1:
self.bitstring += "1" if self.toggle else "0"
elif d0 < d1:
self.bitstring += "0" if self.toggle else "1"
else: #d0 = d1
print "Collision"

self.toggle = not self.toggle

else:
self.t1 = datetime.datetime.now()

def handle_bitstring(self):
with open(OUT_FILE,"ab") as f:
while len(self.bitstring)>=8:
byte_bin = self.bitstring[:8]
self.bitstring = self.bitstring[8:]
byte_int = int(byte_bin,2)
byte_hex = hex(byte_int)
byte_chr = chr(byte_int)
print "%s  %3d %4s %s"%(byte_bin,byte_int,
byte_hex,byte_chr)
f.write(byte_chr)

if __name__ == "__main__":
egc = EntropyGeigerCounter()
while True:
egc.handle_bitstring()
time.sleep(0.1)
```

As we need two ticks to generate one random bit, we produce entropy at half the tick rate. The 2500 events per second result in 1250 random bits per second, or about half a megabyte per hour.

## Testing

We can test the “quality” of the decay-generated entropy with some readily available tools, right on the Pi, namely “rngtest” which is part of the “rng-tools” suite and implements FIPS 140-2 tests and the dieharder testsuite by Robert Brown which contains even more statistical tests.

It should be noted that all these tests can only detect certain patterns in the data. They can pass for non-random data and fail for true randomness. They should only be considered sanity checks and not definitive.

To install the tests, we run:

`  apt-get install rng-tools dieharder `

To test our data with rngtest:

`  cat entropy.bin | rngtest`

Which - after running entropygeiger.py for about 15 minutes - produces the following report:

```rngtest 2-unofficial-mt.14
Copyright (c) 2004 by Henrique de Moraes Holschuh
This is free software; see the source for copying conditions.  There is NO warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

rngtest: starting FIPS tests...
rngtest: entropy source exhausted!
rngtest: bits received from input: 1002488
rngtest: FIPS 140-2 successes: 49
rngtest: FIPS 140-2 failures: 1
rngtest: FIPS 140-2(2001-10-10) Monobit: 0
rngtest: FIPS 140-2(2001-10-10) Poker: 1
rngtest: FIPS 140-2(2001-10-10) Runs: 0
rngtest: FIPS 140-2(2001-10-10) Long run: 0
rngtest: FIPS 140-2(2001-10-10) Continuous run: 0
rngtest: input channel speed: (min=24.205; avg=324.159; max=1362.392)Mibits/s
rngtest: FIPS tests speed: (min=4.671; avg=6.018; max=6.258)Mibits/s
rngtest: Program run time: 169693 microseconds
```

The tests run in blocks of 20000 bit each, and 49 of the 50 blocks passed the test. The single failure is most probably a false positive.

To test with dieharder:

`  dieharder -a -f entropy.bin`

It takes a lot more time than rngtest and outputs:

```#=============================================================================#
#            dieharder version 3.31.1 Copyright 2003 Robert G. Brown          #
#=============================================================================#
rng_name    |           filename             |rands/second|
mt19937|                     entropy.bin|  8.06e+06  |
#=============================================================================#
test_name   |ntup| tsamples |psamples|  p-value |Assessment
#=============================================================================#
diehard_birthdays|   0|       100|     100|0.60524248|  PASSED
diehard_operm5|   0|   1000000|     100|0.28329704|  PASSED
diehard_rank_32x32|   0|     40000|     100|0.14680003|  PASSED
diehard_rank_6x8|   0|    100000|     100|0.66775801|  PASSED
diehard_bitstream|   0|   2097152|     100|0.03547969|  PASSED
diehard_opso|   0|   2097152|     100|0.63643134|  PASSED
diehard_oqso|   0|   2097152|     100|0.58521817|  PASSED
diehard_dna|   0|   2097152|     100|0.49017156|  PASSED
diehard_count_1s_str|   0|    256000|     100|0.90672404|  PASSED
diehard_count_1s_byt|   0|    256000|     100|0.13019764|  PASSED
diehard_parking_lot|   0|     12000|     100|0.72516127|  PASSED
diehard_2dsphere|   2|      8000|     100|0.52175415|  PASSED
[...]
```

## Result

We were able to produce random data from radioactive decay at a steady rate of over 1200 bit per second, using only commonly available hardware and open-source software. The device is conceptually a true random number generator and the output passes statistical tests for randomness.

The inherent unpredictability of the generating process and the rather high output rate make it well suited for key-generation and other applications in cryptography.

## Discussion

, 2023/07/20 09:39

What an awesome post. This is so cool. Thanks for sharing! renovation reserve

, 2023/10/16 07:06

I discovered an untamed area dordle that was so breathtaking that, according to what I discovered, 19th-century artists put themselves in danger by traveling there.

, 2023/10/31 06:50

The information you share is great, please continue to write about this topic regularly flagle

, 2023/12/19 01:53

I hope you will work as hard in the future as you do now. In fact, the way you write has given me ideas quordle

, 2024/01/05 06:32

AtCall Girl in South Ex we have beauties from abroad. Russian blondes with silky hair, curvy face and experience of 69 positions on the bed. We get that foreign escorts bring an air of mystery with them, and many men have built their fantasies around them.

, 2024/01/08 09:12

In the brand-new horror game fall guys, you will be left alone in a large toy factory while being pursued by a terrifying beast. Are you prepared to embark on this journey? Have fun and get started right now!

, 2024/01/17 01:53

I have to admit to everyone that I don't have any knowledge about nuclear molecules but as soon as I read your article I want to learn more about it, I hope you will like it. and also mapquest driving. Thank you again for this interesting information.

, 2024/01/19 07:12

I must confess to everyone that I know very little about nuclear molecules, but after reading your post, I'm eager to find out more. I hope you find it interesting as well. buildnow gg

, 2024/02/07 04:15

The concept is based on pizza tower the fundamental unpredictability of the exact moment of decay in radioactive material.

, 2024/02/12 23:38

Buy a driver's license Hello, welcome to the world's largest online driver's license organization. We sell authentic and registered driving licenses and we have several driving schools with which we collaborate.

What a nice post! I'm so happy to read this. What you wrote was very helpful to me. Thank you. Actually, I run a site similar to yours. If you have time, could you visit my site? Please leave your comments after reading what I wrote. If you do so, I will actively reflect your opinion. I think it will be a great help to run my site. Have a good day.

It is incredibly average to see the best inconspicuous components presented in a basic and seeing way Thank you. Actually, I run a site similar to yours. If you have time, could you visit my site? Please leave your comments after reading what I wrote. If you do so, I will actively reflect your opinion. I think it will be a great help to run my site. Have a good day.

Such an especially significant article. To a great degree charming to examine this article.I should need to thank you for the undertakings you had made for creating this astonishing article. https://cf-cc-qualitylab.com/product/automated-money-developer-machines/

I am another client of this site so here I saw different articles and posts posted by this site,I inquisitive more enthusiasm for some of them trust you will give more data on this points in your next articles.

All things considered I read it yesterday yet I had a few musings about it and today I needed to peruse it again in light of the fact that it is extremely elegantly composed.

Actually, I run a site similar to yours. If you have time, could you visit my site? Please leave your comments after reading what I wrote. If you do so, I will actively reflect your opinion. I think it will be a great help to run my site. Have a good day.

, 2024/02/15 11:24

We have already gained huge fame here. In Dwarka, our Call Girls in Dwarka are very famous for their looks and service. Many men avail service on a daily basis and experience immense satisfaction and pleasure with sexy Dwarka escorts. We have too many girls and you can hire any girl you find attractive.

, 2024/04/06 08:06

Our High Profile Call Girl in Delhi girls are so friendly so you will not have to struggle while interacting with them. They will engage you towards them through their beauty and their smartness. Our escort call girl respects your erotic desire so it is their duty to add fun and pleasure to satisfy you totally.

, 2024/04/13 08:02

if you have selected what form of partner Call Girls Service in Bhopal you want, you could leave the rest to us. diverse people have diverse dispositions that must be tended to in an trade way.

, 2024/04/20 08:30

Things to do in the city are wide, and you have to keep your bucket list ready before traveling in the city. Now, let's talk about the fun in the city. Are you looking for fun-loving girls and mature ladies in the city for sex? Escorts in Dehradun ensures this task is easier because the wide range of girls and beautiful ladies are listed on this portal.

, 2024/04/26 01:08

Central to the Infinite Craft experience is the art of crafting. Players can gather resources from their surroundings and use them to create a myriad of items, structures, and tools.

, 2024/05/17 09:54

This is a fascinating concept that combines principles of physics, mathematics, and computer science. By counting the number of decay events detected by igrofresh the Geiger counter, you can generate a stream of random numbers.

, 2024/05/19 06:46

Love this cake, have made it many times! So moist and delicious! Have you ever made it into cupcake form? Any idea on baking time or<a href=“https://citynightdehradun.com/”>Escort Service Dehradun</a>how many it would make? Thanks!!

, 2024/05/19 06:47

Love this cake, have made it many times! So moist and delicious! Have you ever made it into cupcake form? Any idea on baking time or<a href=“https://citynightdehradun.com/”>Escort Service Dehradun</a>how many it would make? Thanks!!

, 2024/06/18 13:33

By analyzing the timing between successive radioactive decay events, you can extract randomness or entropy. The randomness comes from the inherently unpredictable nature of radioactive free gamesdecay, making it a reliable source of entropy.

, 2024/06/19 03:10

Discover the ultimate drifting experience with Drift Hunters ! Play online now on PC or mobile and master the art of drifting with stunning 3D graphics and realistic physics.

, 2024/06/25 06:27

Currently, I am in the process of developing the talents that you have imparted to me, which are a direct outcome of your great competence. I would like to convey my genuine gratitude for the giving of this vital knowledge. quordle today

, 2024/06/25 11:07

We are one of the best wide range of RK Puram Escort Service who have great portfolio to satisfy your desire, so you are not going to bore while visiting our website! Ask us on WhatsApp for available call girls in RK Puram for tonight meeting and find the which will works best for you!

, 2024/07/14 11:29

There a few interesting points soon enough on this page but I do not determine if they all center to heart. There is some validity but I will take hold opinion until I check into it further. Great post , thanks and that we want a lot more! Put into FeedBurner at the same time seo service UK

, 2024/08/18 16:43

Kubet la nha cai noi tieng voi cac tro choi ca cuoc da dang va chuong trinh khuyen mai hap dan. Website: https://kubet-casino.org/

, 2024/08/23 11:13

123B hay 123Bet la nha cai uy tin hang dau chau A nam 2024. 123 Bet cung cap khong ngung nghi nhung san pham game ca cuoc an tien that toi voi gioi cuoc thu Viet Nam va chau A. Website: https://123bet.casino/

, 2024/08/26 11:04

Appreciate the practical advice. Very useful post! https://medium.com/@mark.randyy/best-1-deposit-casinos-in-canada-cfd7b6b08e15

, 2024/09/03 14:28

en keep constantly thinking about sexual fun and hope to satisfy their needs. They barely get any opportunity to do it. Being one of the main Mature Housewife escorts in Dehradun, it is our duty to provide our premium service to our customers with ease. We have been capable of fulfilling each man’s needs and all kinds of sexual desires. They love getting in touch with handsome men. Low rate 3s00 of Call Girls Dehradun and are exceptionally gifted in delivering whatever is expected from them. With their commitment and eagerness to provide a successful session, they are the best choice for all our regular customers.Our customers know exceptionally well how skilled they are. These days life is exceptionally unpleasant and dull. We can an alternative for such are customers who want to get rid of such a situation to have sex some beautiful ladies. There is no problem to think like this when you are with the gorgeous and sexy women who can make each minute loaded with joy and pleasure. These are exceptionally experienced Call Girls in Dehradun helping you dealing with such situations. They know exceptionally well what men like when they call such amazing babes of the town.

, 2024/09/04 13:27

Our Independent Delhi Escorts Are Hand-Picked And Meticulously Vetted For Their Allure As Sex Models. They Will Go Above And Beyond To Make Sure You Have A Nice Time Since They Know How To Pleasure A Man.

, 2024/09/07 10:34

Our escort agency is home to many beautiful and top-ranking adult entertainers. We are here to provide you with high-end Connaught Place escort services. All these services are very premium and top-rated Escorts in Connaught Place We are available with numerous escorts who are perfect for your adult entertainment.

Enter your comment. Wiki syntax is allowed:
C O J X R