This project simulates a lottery where the winning number is generated with quantum randomness and then found efficiently using Grover's Algorithm.
This system first creates a quantum-generated winning number. Instead of checking all possible numbers one by one (classical brute force), it uses Grover's Algorithm to find the winning number efficiently in an unsorted search space.
A random number is generated using quantum superposition:
- Hadamard (
H) gates are applied to all qubits. - Each qubit enters a state that can represent both 0 and 1.
- After measurement, a random binary string is produced.
That measured string becomes the winning lottery number.
Example for 2 qubits: possible outputs are 00, 01, 10, 11.
All possible qubit combinations are treated as an unsorted database.
For n qubits, total possible values are:
2^n
The quantum-random winning number is one of these values and is the target to be searched.
Grover's search uses two core components:
- Oracle
- Marks the target (winning number) by phase inversion.
- This tags the correct state.
- Diffusion Operator
- Amplifies the marked state's amplitude.
- Decreases amplitudes of non-target states.
- This is amplitude amplification.
One Grover iteration = Oracle + Diffusion.
- For small systems (for example, 2 qubits), one iteration is often enough.
- Larger systems require more iterations to maximize success probability.
After Grover iterations, the circuit is measured. Because the target state's probability is amplified, it appears most frequently in outcomes.
Results are shown as a histogram. The winning number should have the tallest bar.
- Generate random winning number via quantum superposition.
- Build Grover search over full unsorted space.
- Amplify the winning state's probability.
- Measure and observe the winner with high frequency.
- Python
- Qiskit
- Qiskit Aer simulator
- Matplotlib
- Tkinter interface (desktop UI)
- Secure random number generation
- Quantum search systems
- Cryptography concepts
- Optimization problems
This project demonstrates how quantum computing can reduce search effort in large unsorted spaces. It highlights Grover's Algorithm's advantage over classical search and shows how quantum randomness can be used in lottery-like applications.
python3 -m venv .venv
source .venv/bin/activate
pip install -r requirements.txtpython3 quantum_lottery.py --qubits 2 --shots 2048python3 quantum_lottery_tk.pyThe script prints:
- quantum-random winning number
- Grover iteration count
- measured most frequent result
- whether the measured top result matches the winning number
It also saves:
grover_lottery_histogram.png