Statistical Tests for My Audio Based Random Number Generator


  1. Get audio sample from the microphone.
  2. Push the least significant bit to a buffer.
  4. Apply the hash function on the buffer.
  5. Get random bits from the digest.


 * Copyright (C) 2010  Guy Rutenberg
 * (at your option) any later version.
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * GNU General Public License for more details.

#include <cstdio>
#include "md5.h"

class Grandom {
		virtual ~Grandom();
		 * Generate a random dword
		uint32_t operator()();
		void gather_entropy();
		void get_block();
		FILE* m_dsp_fd;
		uint32_t m_index;
		union {
			char digest[16];
			uint32_t v[4];
		} m_buffer;

		md5_ctx m_md5_ctx;
		uint32_t m_block[512/32];

The Grandom class uses MD5 as the hash function, 16-bit samples and 44.1KHz sampling rate. This configuration should work well on any modern sound card. The full implementation is available in grandom-1.0.tar.bz2, which is a small test app.

To have some evidence for the quality of the random number generation I’ve tested it against NIST’s statistical test suite. I’ve tested 320 streams of 1M bits each. The results showed that the random number generator passed all of the tests but one (one of the non-overlapping pattern test, although it was very close to pass). If you wan to see the results, take a look at the final analysis report.

Overall, Grandom seems to be a good way to generate small amounts of high quality random numbers.

Leave a Reply


