# How to Use a Random Number Generator to Create Uncertainty in PCB Design

Created: November 16, 2017
Updated: June 9, 2020

My high school peers knew me as a predictable person—always the first one to show up anywhere—on time, every time. Since they didn’t seem as concerned with keeping their schedules and promises, sometimes I waited hours for my friends. That uncertainty would mess up my schedule, but engineering was a place where I found uncertainty was rarely a problem. Unsurprisingly, I developed a deep interest in physics and engineering, where the results are predictable and based on the inputs provided.

Predictability is a great asset in embedded system design, especially in critical applications and running tests. But predictability has been my downfall once or twice, too. Specifically, I was working on creating a random number generator within an embedded system, and it took me many attempts before I was able to utilize uncertainty and make an array randomly shuffled.

## Randomness in Embedded Systems

Embedded systems need to have smooth communication in order to enable their operations, and oftentimes this communication takes place in binary 1s and 0s. Even analog designs need minimum interference to deliver a stable signal. An embedded system can live and breathe by a strong random number generator. This seems counterintuitive, right? But it’s true—uncertainty can be more desirable in some of your potential systems.

One of my projects involved designing customized MP3 players that are used to broadcast music at premium retail outlets. One requirement was for it to randomly shuffle a playlist in a way that a different song is played at the beginning of every day. The requirement stressed that there must not be any pattern in the choice of songs being played, even against other MP3 players. So how do we accomplish this? Through assigning a formula for uncertainty.

## Pseudo Random Number Generators

Shuffling the songs in the MP3 player can be easily achieved with a pseudo-random number generator (PRNG), which is a mathematical formula used to generate sequences of random integers. It is a quick way to introduce any form of randomness in an embedded system.

It uses a seed number to generate the first sequence and can continuously generate random sequences thereafter. However, it is not a pure random number algorithm as these sequences would eventually be repeated in time. And, if two or more devices share the same seed number, the initial sequence would be identical. A duplicate sequence ensures predictability, and therefore does not create uncertainty.

In my case, I used the various timer values in the microcontroller to generate the seed number, hoping that the result of the song shuffle would be unpredictable, at least to the human ear. My hopes were dashed when listeners complained that each of the MP3 players started playing a particular song on the list almost every time they were turned on. Back to the drawing board.

## The Best Unpredictable Source of Randomness: White Noise

Using timer values as seed numbers made the randomization predictable; the randomization process is executed during the initialization of the MP3 player. By extension, any usage of predictive variables like date or time as seed numbers also made the randomization predictable. This was an expensive oversight for me in my project that resulted in a revision of the hardware design to bring true randomness in the shuffling. What did I end up doing?

I merged a deterministic PRNG and a random white noise generator in order to find the perfect solution in creating randomness for my MP3 player’s shuffling. To allow a better variation of the random value, use an operational amplifier to magnify the noise. This random value can then be used as the seed number for the pseudo-random number generator algorithm.

Whatever solutions you come up with for your need for uncertainty, it is important to isolate the source signal for your randomness. Otherwise, there might be interference and system-bias which creates predictability, which is anything but the goal here. True randomness and signal isolation are hard to achieve, and especially hard to think of by yourself. That’s when setting the right Design Rule Check (DRC) in PCB design software like CircuitStudio® helps.

Need more help in creating true random number generators in your hardware? The solution’s at your fingertips in our software. Talk to an expert at Altium now and find yours.