Inspiration
https://www.youtube.com/watch?v=4R5xnTAvBgc https://www.youtube.com/watch?v=ZBaXPY_0TNI https://medium.com/@jonathonkischuk91/complex-numbers-and-probability-theory-in-quantum-computing-e85dc8848374 "if a qubit is in the state: ∣ψ⟩ = 1/√2∣0⟩ + i/√2∣1⟩ Then the probability of measuring ∣0⟩ or ∣1⟩ is: P(0) = ∣1/√2∣² = 1/2, P(1) = ∣i/√2∣² = 1/2" https://quantum.cloud.ibm.com/docs/en/tutorials/hello-world https://arxiv.org/pdf/2511.02901
"from scipy.stats import chi2_contingency
data = [[207, 282, 241], [234, 242, 232]] stat, p, dof, expected = chi2_contingency(data)
alpha = 0.05 print("p value is " + str(p)) if p <= alpha: print('Dependent (reject H0)')
else: print('Independent (H0 holds true)')"
https://www.geeksforgeeks.org/python/python-pearsons-chi-square-test/
plot_histogram(counts)
%%
from qiskit import QuantumCircuit, transpile, Aer, execute
qc = QuantumCircuit(2, 2) qc.h(0) qc.h(1)
qc.measure([0, 1], [0, 1])
simulator = Aer.get_backend('qasm_simulator') job = execute(qc, simulator, shots=1000) result = job.result()
counts = result.get_counts(qc) print("Measurement results:", counts) print(qc.draw())
What it does
This circuit uses the Hadamard gates on each qubit so that it rotates the qubit and gives it a 50% chance of having a final state of |1> and a 50% chance of having a final state of |0>. For an output to truly be random, they each have to have equal probabilities; therefore, with this in mind, I used a quantum circuit to generate random numbers (the final state of the qubit). With 1024 shots, each outcome was shown to be close to equally likely. I ran the code a few times (10 times) to get certain outputs, and with these, I then used Chi-Square to prove that the numbers/outputs were truly random. To reduce the errors that could be caused by noise, I considered using zero-noise extrapolation.
How we built it
I built a circuit with four H gates, and at the end, I measured each qubit's state. Since each potential output had an equal chance of being measured, the sequence of 0s and 1s from each qubit's state would be a random number.
This is the circuit that I used:
circ = QuantumCircuit(5,5) circ.h(0) circ.h(1) circ.h(2) circ.h(3) circ.h(4) circ.barrier() circ.measure(0,0) circ.measure(1,1) circ.measure(2,2) circ.measure(3,3) circ.measure(4,4)
circ.draw("mpl")
from qiskit_aer import AerSimulator from qiskit import transpile
simulator = AerSimulator() circ_transpiled = transpile(circ, simulator) result = simulator.run(circ_transpiled).result()
counts = result.get_counts(circ_transpiled) print("Measurement result:", counts) circ.draw(output="mpl")
I then used qiskit_aer for the simulation, where every time you run the code, the output is a random sequence of 1 and 0.
Challenges we ran into
It was a bit hard to understand what the prompt was asking; however, after looking over videos and some tutorials, I had a gist of what it was asking for. Another challenge I ran into was error mitigation. I installed visual studios to be able to run my code and visualize it. This is my first time exploring quantum computing; therefore, it was a bit hard to understand everything clearly. Another challenge I ran into was being able to run the circuit itself to generate random numbers, as I did not have qiskit -aer, I installed it and kept running into different errors that were related to qiskit_aer or Visual Studio. Running my code would result in an error when using qiskit_aer.
Accomplishments that we're proud of
I am happy to be able to do my first hackathon. I am proud of using what I already know to apply to the new things I learned at this festival. Quantum computing was completely new to me, and I learned a lot about it throughout the three days of this event. I am proud of being able to solve the many problems I had with my code at the start.
What we learned
I also discovered how crucial it is to generate truly random numbers. This could be useful for exchanging information and enhancing its security. The example of Alice sending a message to Bob, which required them to generate a key from the many states of the qubit they selected, helped me comprehend this. The key would consist of each state from Alice that corresponded with Bob's. The key would not reveal a message if someone interfered, indicating that someone was doing so.
What's next for Quantum Random Number Generator
Discovering a more efficient way to do this and generate random numbers. I believe that although this generator is truly random with its sequences of zeros and ones, there could be other ways to make it a random number generator, with the possible outputs going up to infinity.
Built With
- python
- qiskit
Log in or sign up for Devpost to join the conversation.