Skip to content

Radioactive decay based random number generator using Geiger counter, STM32 and HAL.

License

Notifications You must be signed in to change notification settings

ufnalski/geiger_muller_tube_true_randomness_g474re

Repository files navigation

Radioactive decay based random number generator on steroids (STM32G474RE)

An STM32 HAL example of a true random number generator using a Geiger counter.

Important

The experiment can be carried out in two ways: a totally safe one using a background radiation around us and a doped one using uranium ceramic. Both of them let you generate a stream of truly random bits. The difference lies in the bitrate they offer. In my case the background radiation was insufficient to generate, in a reasonable time frame, a stream of bits long enough for some conclusive statistical testing of its randomness.

Caution

Dope your Geiger counter with a radioactive sample if and ONLY if you know what you are doing ❗ Even if individuals can in you country legally buy samples of uranium ore/ceramic1, such materials require proper handling to be considered safe for human health. Educate yourself on the topic before you make any purchasing decisions - and it is not only about its radioactivity ☢️ but also about its toxicity 🤮

Uranium ore in action

Uranium ceramic sample inside the counter stuck to the tube - hence the over standard readings:

Uranium ore in action

The algorithm itself is extremely simple. As the decay events are fundamentally unpredictable it is sufficient to measure time span between four consecutive event detections and compare the length of two time intervals to generate a random bit. In my case the resolution of HAL_GetTick() proved to be sufficient to pass selected tests for randomness collected by NIST in "A Statistical Test Suite for Random and Pseudorandom Number Generators for Cryptographic Applications"2. Why just selected ones? All ones that can be performed on ca. 100 000 bits. Some tests have to be performed on much longer streams to be considered conclusive. My generator operates at the level of 30 random bytes per minute. Generating of 1 000 000 bits would take ca. 3 days. Doable but still not accomplished at the time of writing. And this something definitely in my mind - notice the Winbond W25Q128 in the photo 🙂 Two tests require even more bits than that, e.g. 10 000 000 bits are recommended3.

The low bitrate of TRNGs is not something uncommon. They can be used as an entropy source for PRNGs that can offer higher bitrates4.

Tip

If the resolution of 1 ms is not sufficient in your case, go for a timer in the input capture mode.

Missing files?

Don't worry 🙂 Just hit Alt-K to generate /Drivers/CMCIS/ and /Drivers/STM32G4xx_HAL_Driver/ based on the .ioc file. After a couple of seconds your project will be ready for building.

Libraries

Software tools

Capture tab

Exemplary hardware

Readings and videos

The test suite (exemplary implementations)

The last one is perfect for newbies - you just ctrl+c ctrl+v the bitstream and hit the button. Note that some tests require at least one million of bits to be conclusive. I generated ca. 100 000 bits. Half of the tests are flagged as erroneous due to the insufficient number of bits. The other half is passed.

NIST test suite results

I will stop tests here to proceed to other sources of entropy. Some of them happen to be quite attractive visually5 - I have to build one using STM32 (with HASH and DCMI peripherals) and OV2640. An ESP32 version has just been completed in the meantime of editing this README.md and it passes all the NIST tests without any lava lamps, just by staring at the celling. Apparently the CMOS image sensor noise does the necessary job. Nevertheless, I have to investigate it further before I can give any conclusions on it - saying anything with certainty about the randomness can be tricky 😄

Call for action

Create your own home laboratory/workshop/garage! Get inspired by ControllersTech, DroneBot Workshop, Andreas Spiess, GreatScott!, ElectroBOOM, Phil's Lab, atomic14, That Project, Paul McWhorter, and many other professional hobbyists sharing their awesome projects and tutorials! Shout-out/kudos to all of them!

Warning

Automation and control engineering - do try this at home ❗

190+ challenges to start from: Control Engineering for Hobbyists at the Warsaw University of Technology.

Stay tuned!

Footnotes

  1. Sprawdź licznik Geigera czy działa?! URAN spiek

  2. Random Bit Generation (National Institute of Standards and Technology)

  3. NIST random excursion results (StackExchange)

  4. Hardware random number generator (Wikipedia)

  5. The Randomness Problem: How Lava Lamps Protect the Internet 🌋 + Method for seeding a pseudo-random number generator with a cryptographic hash of a digitization of a chaotic system

About

Radioactive decay based random number generator using Geiger counter, STM32 and HAL.

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published