December 03, 2016 by Marco Cecconi
Winter Bash is a festive celebration of Stack Overflow and Stack Exchange communities. People compete to be awarded crazy hats for completing random, and often undisclosed actions. I've been involved in building a lot of this year's celebration, which will start soon and will be kept secret until then.
Last year we had a hat referencing "the dress", which at the time was a hugely popular meme. The hat that could be won would be black and blue or white and gold depending on the user receiving it. Well, a little known secret is that this was achieved by using looking up the bit corresponding to each user's account id in a file, and that file was an actual image of the dress. Pretty neat, eh?
This year we also needed a source of "replicable randomness". While we could have used the same means, why not over do it? So I took an afternoon off and built a hardware RNG. Only the randomest bits for Stack Overflow! This post talks a bit about how I did it.
The first step was to find a plan for a hardware RNG that was simple enough, and with common enough components, that I could just build it with my existing stash of parts. What I found was an extremely simple circuit design based on avalanche noise in a reverse-biased PN junction. In other words, two transistors are connected the wrong way and oscillate randomly. A third transistor amplifies the noise. Finally the random noise is sent to an Arduino port, digitized and then cleaned up.
Here's what the circuit looks like.
It's amazing that such a simple circuit could output quantum randomness, at least to me :-)
Here's the bill of materials if you want to build it yourself:
|C1||Electrolytic Capacitor, 10µF|
|C2||Ceramic Capacitor 0.1µF|
|Part1||Arduino Uno (Rev3)|
|Q1-Q2-Q3||3 × TRANSISTOR 2N2222|
All was assembled on a mini bread board and the (untidy) result was this.
Before we proceed further, I want to make it clear that in order to build this, I followed the instructions of another blogger, Rob Seward. All kudos are to him, not me!
I've hooked up my cheap Hantek 6022 USB scope to ground and A0, and here's what the output looks like: a randomly oscillating voltage, between ±100mA.
The software, also written by Rob, implements two algorithms to remove bias from the source. A XOR filter an a Von Neumann randomness extractor. Both are simple state machines that are well adapted to Arduino's C variant.
The output is finally sent to the serial port as a series of zeros and ones, and then converted to an actual bin file by this simlple linqpad script.
And there you have it! Now we have the best possible hardware generated random bits to assign winter bash hats to Stack Overflow users, nicely packaged in a .bin file so we can replicate the exact same sequence on all platforms!
Yes, the irony of this post does not escape me.
Hi, I'm Marco Cecconi. I am the founder of Intelligent Hack, developer, hacker, blogger, conference lecturer. Bio: ex Stack Overflow core team, ex Toptal EM.Read more
October 15, 2021 by Marco Cecconi
Multiple people with my name use my email address and I can read their email, chaos ensues!Read more
September 29, 2021 by Marco Cecconi
After years of building, our top-notch consultancy to help start-ups and scale-ups create great, scalable products, I think it is high time I added an update to how it is going and what's next for us.Read more
February 03, 2021 by Marco Cecconi
A lesson in building communities by Stack Overflow's most prominent community manager emeritus, Shog9Read more
December 02, 2020 by Marco Cecconi
Some lessons learned over the past 8 years of remote work in some of the best remote companies on the planetRead more
$ wget -O - hackurls.com/ascii | lessRead more…