Quantum Random Number Generator


The purpose of this post is to share a simple design of a quantum random number generator (QRNG) over a USB link to PC.

The QRNG extrapolates randomness from photon counting during a time window using an LED as photon receiver, wich allows a low cost design. The generated randomness successfully passes the NIST SP 800-22 statistical test suite[1].


Block diagram

QRNG block diagram
QRNG Diagram

The QRNG is made of four main parts :

  • The photon receiving part using an LED
  • The comparator
  • The counter
  • The microcontroller

Photon receiving using an LED

It is known that the LED is able to work as a light detector in the same way as a photodiode[2]. The first step is to find an LED compatible with photon detection, after testing several references, it seems that GaP LEDs are more suitable for this purpose, compatible references are for example AND113R or L-53HD. The LED is reverse biased with a bias voltage of ⁓20V, I resistor amplify the detection pulse. Finally the reverse biased LED is placed in front of an other LED wich emit light.

Reverse biased LED
Reverse biased LED

The signal of the generated pulse event with R=200kΩ:

Photon detection pulse

Event statistic analysis

We are now able to detect photon detection event, the next step is to study the statistics of these event. For this QRNG, the idea is to count photon detection events during 500µs (this function will be seen later in the comparator part), then to use the parity to generate a “1” or “0”, by counting 1000 times the events of a 500µs time window, then plotting the results, it gives us an idea of the distribution of the events :

In blue : distribution of photon detection events, in red a theorical Poisson distribution

The result shows that the detected photon distribution follows the theorical Poisson distribution wich tells us that event are trully (quantumly) random.


To be able to count events, it is mandatory to digitize the analog signal of the events. To do so, a simple comparator circuit is used with a level detection of 100mV :

Comparator circuit

The comparator circuit use a LM311 powered by +5V from the USB, the Vref (100mV) is provided by the microcontroller, the Vimpulsion is the signal from the photon detection event. The circuit output a numeric signal wich will be the input of the counter.


Now, we need to count pulses during 500µs, in the reality, we will count during 498µs, then we will process the information during 2µs, wich allows a 2kHz bit rate generation. To do so, we use a counter driven by the microcontroller :

Counter circuit

The three most important inputs of the counter are ENP, CLR and CLOCK. The ENP input enables the counting when state is “1”, the CLR input clear the counter data register when state is “0” and the CLOCK input is simply the signal from the comparator.

To drive ENP and CLR inputs, we use two PWM channels of the microcontroller. The philosophy is to set two 2kHz pulses, the first one will have 498µs pulse width for the ENP input to enable the counting, and the second one a 499µs pulse width for the CLR input to clear the data register. Our microcontroller will implement an interruption on the falling edge of the ENP signal, when the interruption is raised, the microcontroller read the LSB bit of the counter, wich correspond to the parity, then save the value in a 8 bits variable, when 8 values are read, the byte is sent over the USB link.

ENP pulse in yellow, CLR pulse in blue.


The required microcontrolled does not need many features, just an analog output to provide reference for the comparator, two PWM channels able to generate 2kHz signals with 498µs and 499µs pulse width, a digital input to read the counter, and a serial or USB interface. I choose the teensy USB development board, wich has very good characteristics and is easy to use for a low price, if you choose a microcontroller with only serial bus without USB, you can add a FTDI serial to USB wich works very well.

The microcontroller programming is quite easy, the code sample below shows the interrupt management, the most tricky part. The pin 15 is the LSB of the counter, the pin 8 is the ENP signal. (Teensyduino is used as IDE).

volatile byte count=0;	
volatile byte rndm=0;

void interrupt() 
  if (count<8)
  	rndm |= digitalReadFast(15);
  	count += 1;

//interrupt configuration
pinMode(8, INPUT_PULLUP);
attachInterrupt(digitalPinToInterrupt(8), interrupt, FALLING);

The main program just manage the byte sending :

if (count>7)
	rndm = 0;
	count = 0;

Statistic test results

I unput a 1MB binary sample of generated random numbers in a software tool wich tests the first three tests of NIST SP 800-22 statistical test suite, and they all pass :


[1] A Statistical Test Suite for Random and Pseudorandom Number Generators for Cryptographic Application.

[2] Forrest M. Mims III, “Using LEDS As Light Detectors,” May 1977, 86-88.

Begin typing your search term above and press enter to search. Press ESC to cancel.

Back To Top