White Noise for Random Numbers

Some time ago, a good friend of mine asked me to help him create a non algorithmic source of random numbers for a cryptography project he's working on.  To keep things as simple as possible, I decided to start with a source of white noise from a zener diode and then feed this into the microphone input on my computer.  Then, using software, I planned to munge the digitized noise values into something a bit more uniformly distributed using the CRC-32 algorithm.  The page describes my efforts and presents a simple design you can build and use.  You may also find other uses for this white noise generator in audio applications and in filter design.

For my first effort, I tried using an old AM, transistor radio tuned to pick up the static heard between channels.  This actually seemed to work fairly well, but the AM radio also tended to pick up a buzz-like RF interference when I connected the it to my computer.  So, I decided to build a white noise generator based on using Shot noise from a reverse-biased zener diode.

My first source of white noise

(clock for larger view)

There are a number of circuits for this on the Internet, but the design I settled on was adapted from an EDN Design Idea, that I modified it to have only one, line level output.  Deciding, instead, to use the left over op amp as a voltage follower. I also added a DPDT switch for on/off control. and an LED to indicate when the circuit was powered on  Please read the original article for details on the design and how it works.  The schematic for my revised circuit is, as follows:

Next, I did a simple PCB design using Osmond PCB and fabbed the design using OSH Park (click here to order 3 copies of the PCB for $6.05.)  The following image shows the top surface of the PCB which shows the component layout relative to the schematic above:

The parts list for the white noise generator is listed below, or you can click this link to order a complete set of parts from Mouser for less than $7 (US), excluding shipping costs.  Note: prices and component availability may change with time, so you may have to substitute components if some are out of stock.

White Noise

Here's what the white noise generator looks like after all the components are soldered in and it's connected to two, 9 volt batteries to power it:

Click for larger view

Testing the White Noise Source

To test the White Noise Source, I connected the output to my MacPro's line input jack (using a microphone input jack may require you to use an Attenuator Cable to drop the signal level down to one the microphone input can handle) and then selecting this source is the audio input in the "Input" pane of the "Sound" control panel in "System Preferences":

Click for larger view

At the same time, adjust the "input volume" slider so the level shown in the "input level" indicator goes to nearly full scale but, to prevent clipping, make sure it does not go beyond the 2nd highest indicator dot.

Next, I used the free audio editor program, Audacity, to capture a sample of the white noise waveform for analysis.  I adjusted the controls to capture about 6 seconds of white noise at 16,000 samples/second using 16 bit PCM and then used the "Plot Spectrum" tool in the "Analyze menu to get this:

Click for larger view

As you can see, the spectrum plot is quite flat across the frequency range expected for a 16,000 samples/second recording.

Generating Random Bytes

Next, I wrote a simple Java 8 program to use the java.sound API to capture white noise samples and and convert them into random bytes using the CRC-32 algorithm available in the java.util.zip package.  You can download the program (and source code) below.  While I wrote and tested the code on a Mac, it should run fine on other systems running a version of Java 8, or later.  The executable program comes packaged on a .jar file so, to run it from the command line, change to the directory containing the .jar file and type the following command:

java -jar RandomGen.jar 100000

This will cause the program to generate an output file named random.bin that contains 100,000 random bytes.  Alternately, you can specify the output file name by adding an additional parameter, like this:

java -jar RandomGen.jar 100000 file.bin

I've also included a random.bin file you can download and use to run some simple randomness tests, if you're so inclined.  The file is only 100,000 bytes in length, so that limits the kids of tests you can run, but it should give you an idea of what this approach can produce.