Generating random numbers with an ATtiny45

A HackADay forum member by the name of Karl wanted a hardware-based random number generator. His two primary criteria? Keeping costs low and ensuring sufficient generation of arbitrary numbers.

The solution? Atmel’s ATtiny45 microcontroller (MCU), paired with a USB/serial converter, three wires and a DIP socket.

“Some projects either require expensive parts (geiger tube), are quite big (lava lamp), or are not random enough. Also most of the projects require some soldering experience, which can be a problem for newbies,” Karl explained in a HackADay forum post.

“I was not happy with the options I found. Luckily I stumbled upon the Entropy library for AVR’s. I checked the results from authors’s web site. I also did a few tests on my own by creating a 1mb sample of random data. I was pleased with the quality of the random numbers.”

As HackADay’s Brian Benchoff explains, the AVRentropy uses the watchdog timer’s jitter in AVR microcontrollers to provide cryptographically secure random numbers.

“Setting up the circuit was easy – an ATtiny45 microcontroller was connected to an [inexpensive] USB to serial converter. Three wires, and the circuit is complete. The code was simple as well; it’s just a call to initialize the entropy and write the bits to the serial port,” Benchoff added.

“There are a few drawbacks to this build. Because the entropy library must wait until enough entropy is gathered, it can only produce about two 32-bit numbers per second. That’s all Karl needed for his application, though, and with an enclosure made from a wine cork and marble, he has the prettiest and smallest random number generator around.”

Interested in learning more about a hardware-based platform to generate numbers based with an ATtiny45? You can check out the original forum post here.

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s