I built a random number generator using Quantum Computing

Ghostfreak - Jul 16 - - Dev Community

If you have a basic understanding of quantum computing, you might have heard about principles like quantum superposition. Where, e.g. a qubit (a bit with quantum superpowers) coexists in multiple states until it's measured. Once it's measured, its superposition property vanishes to give us either of the corresponding classical states, which in this case are: 0 and 1.

With this principle in mind, we can use libraries like qiskit to make a simple random number generator.

The Python code is as follows:

import qiskit
from qiskit_aer import AerSimulator

def getrandint(n):

    simulator = AerSimulator()

    qr = qiskit.QuantumRegister(n)
    cr = qiskit.ClassicalRegister(n)
    qc = qiskit.QuantumCircuit(qr, cr)

    qc.h(qr)
    qc.measure(qr, cr)

    job = simulator.run(qc, shots=1)
    return job.result().get_counts(qc)        
Enter fullscreen mode Exit fullscreen mode

In this code block, we first create n qubits and n bits, then make a quantum circuit using them.

Then we perform Hadamard operations on the qubits to take them to a quantum superposition state. Finally, on measuring the qubits into classical bits, the measured information is stored in the classical bits, which are then extracted and returned by the function.

Now the question arises, are the generated numbers truly random? Even if these are, how do we prove them? What do you think?

.
Terabox Video Player