Real Random Number Generator
Using The Ambient Noise

About The Project

This project is about the generation of real random numbers using the noise (sound) of the environment.

Technical Description

This project is developed using C programing language, the /dev/dsp (digital signal processor) on Ubuntu and the soundcard.h header for the sound card settings


/dev/dsp is the digital sampling and digital recording device, and probably the most important for multimedia applications. Writing to the device accesses the D/A converter to produce sound. Reading the device activates the A/D converter for sound recording and analysis.

The name DSP comes from the term digital signal processor, a specialized processor chip optimized for digital signal analysis. Sound cards may use a dedicated DSP chip, or may implement the functions with a number of discrete devices. Other terms that may be used for this device are digitized voice and PCM.


Specifies the sound card settings.

SOUND_PCM_WRITE_BITS: Sets the sample size, in bits. Valid choices are 8 and 16, but some cards do not support 16.

SOUND_PCM_READ_BITS: Returns the current sample size, which should be either 8 or 16 bits.

SOUND_PCM_WRITE_CHANNELS: Sets the number of channels (1 for mono, 2 for stereo). When running in stereo mode, the data is interleaved when read or written, in the format left-right-left-right.

SOUND_PCM_READ_CHANNELS: Returns the current number of channels, either 1 or 2.

SOUND_PCM_WRITE_RATE: Sets the sampling rate in samples per second; the driver will round the rate to the nearest speed supported by the hardware, returning the actual (rounded) rate in the argument. Typical lower limits are 4 kHz; upper limits are 13, 15, 22, or 44 kHz.

SOUND_PCM_READ_RATE: Returns just the current sampling rate. This is the rate used by the kernel.


According to Wikipedia and the Oxford English Dictionary random means:

Having no definite aim or purpose; not sent or guided in a particular direction; made, done, occurring, etc., without method or conscious choice; haphazard.

And this is the basis of this project; create a source of real random numbers that are generated by processing the sound or noise of the environment and transforming it into an integer number.

In C programing language exist such functions that can generate pseudo-random number like rand() or srand(). But those functions are based on mathematical processing:

int rand() /* from K&R produces a random number between 0 and 32767.*/ { ­rand_seed = rand_seed * 1103515245 +12345; ­return (unsigned int)(rand_seed / 65536) % 32768; }

Experimental Data

Next, I'll show some data collected with the application. The microphone start recording 4 bytes of sound into a buffer which is read from /dev/dsp and save it into a .txt to construct a graph that will show the dispersion of the generated numbers. I took 10 samples, each one with 100 randomly generated numbers (click on the image to enlarge it):