###### Technical Articles

True randomness with Quantum ( Quantum Random number generator )

Randomness can be defined as the quality or state of lacking a pattern or principle of organisation, in simpler terms it means unpredictability. Although we as humans can provide a truly random answer for a naive question like chose a number between 1 to 10, for a program the same task is near to impossible. And hence most of the random number generators available today are pseudo random number generator.

What is Pseudorandom number generator?

Random number generators that rely on a mathematical algorithm that is deterministic in nature are called Pseudorandom number generator (PRNG). Software-generated random numbers are only pseudorandom since they rely on a seed number which if know can generate the same sequence of random numbers.

Few examples of the same are FM QF05_RANDOM_INTEGER from ABAP world, Random.randint() from python.

Then the question arises what can be considered as truly random? The outcome of a coin toss since centuries is considered as random and used in many areas like sports, but can an output of a coin toss be really considered as a random event. Provided the set of inputs like initial state of a coin, rotation speed and height of flip etc., can the outcome not be determined ?

Realistically this cannot be done in the short interval, but theoretically the same is possible and hence many studies have discredited coin toss as a valid randomisation method.

What is True random number generator?

Random number generators that rely on external physical variable that is unpredictable like radioactive decay of isotopes or airwave static, rather than by an algorithm are known as True Random number generators (TRNG).

In this blog we will explore true randomness with help of qubits using Qiskit. To be concise a true random number can be generated using below piece of code and the simplest of circuits in quantum computing.

This circuit provides a true random number between 0 – 255 in binary format.

( Please note this 8 bit example has been executed on a qasm_simulator )

To really understand what the above circuit does and how it can generate true randomness we need to answer the below questions.

- What is a qubit and how can it be visualised?
- What is the state of qubit?
- What is superposition?
- What is a Hadamard Gate?

What is a qubit how can it be visualised?

A qubit is essentially the basic unit of information in quantum computing very much comparable to a bit in classical computing and is usually visualised by a Bloch sphere. The basic difference between qubit and bit is that unlike bit a Qubit can have states other than 0 and 1.

What is the state of qubit?

A qubit state is represented by the below equation.

Where is the probability of state being 0 and is the probability of state being 1.

Unlike a classical bit the state of a qubit is unknown until it is measured, once measured in standard Z basis the state either collapses to 0 or 1 represented by below.

What is superposition?

Superposition is a state where in a qubit has a possibility of being 0 or 1.

Few possible superposition states can be + and – where in possibility of qubit being 0 and 1 is equal, this is usually represented by the below 2 states on a Bloch sphere.

When any of these states is measured in standard bases the probability of 0 and 1 is ½, i.e. it is likely that the result can be 0 or 1.

This superposition in a qubit is the basis for generation of truly random number in our circuit.

What is a Hadamard Gate?

The Hadamard gate (H-gate) is a fundamental quantum gate. It allows us to move away from the poles of the Bloch sphere and create a superposition of 0 and 1.

The above circuit takes initial state of 0 and 1 to a superposition state where in measurement can result into 0 and 1 with ½ probability (i.e., the result is truly random).

When the same is performed on 8 qubits it results into a random binary number between 0 – 255.

Another version of the same can be constructed using below circuit iteratively (8 times in our case) to generate the same result.

Conclusion

Since the above 8 bit example uses properties of a qubit to generate randomness the resultant number can be considered as a truly random number as there is no way of predicting the same.

A similar 5 qubit circuit when executed on quantum backends like ibmq_manila ( 5 qubit ) generates a truly random number between 0 – 31.