This project implements a robust Quantum Random Number Generator (QRNG) utilizing IBM Quantum's cloud-based quantum computers. Unlike traditional pseudo-random number generators (PRNGs) which operate on deterministic algorithms, this QRNG leverages the inherent, fundamental randomness of quantum mechanics. By measuring qubits in a state of superposition, it produces truly unpredictable bits, making it uniquely suited for applications requiring the highest level of cryptographic security and genuine unpredictability.
This repository serves as a public demonstration of my capabilities in quantum computing and high-security randomness generation.
The core mechanism of this QRNG is based on the principles of quantum mechanics:
- Quantum Circuit Initialization: A quantum circuit is constructed, containing a specified number of quantum bits (qubits), corresponding to the desired length of the random bit string.
- Creating Superposition: A Hadamard gate is applied to each qubit. This gate places each qubit into a superposition state, meaning it exists as both
0and1simultaneously until measured. This is the source of the quantum randomness. - Quantum Measurement: The superpositioned qubits are then measured. The act of measurement forces each qubit to "collapse" into a definite state – either
0or1– with a 50/50 probability. The outcome of this collapse is inherently random and cannot be predicted. - Bit String Extraction: The individual measurement outcomes from all qubits are concatenated to form a single, truly random bit string (e.g., "101100101011").
- Execution on Quantum Hardware: The prepared quantum circuit is executed on a real IBM Quantum processor (like
ibm_sherbrookeoribm_brisbane) to ensure the generation of genuine quantum randomness. A fallback to a local simulator is provided for development or in cases of hardware unavailability.
- True Quantum Randomness: Generates random numbers rooted in the fundamental unpredictability of quantum mechanics, offering superior entropy compared to classical methods.
- IBM Quantum Hardware Integration: Seamlessly connects to and utilizes high-performance IBM Quantum processors such as
ibm_sherbrookeandibm_brisbanefor real-world quantum computation. - Automated Backend Selection: Intelligently attempts to connect to preferred quantum processors. If the primary choice is unavailable or non-operational, it automatically searches for and utilizes other available operational IBM Quantum backends.
- Robust Local Simulation Fallback: Includes a robust fallback mechanism to a local Qiskit Aer simulator, ensuring the generation process can always proceed for development, testing, or during periods of quantum hardware downtime.
- Customizable Bit Length: Supports the generation of random bit strings ranging from 8 to 256 bits, allowing for flexibility based on specific application requirements (e.g., cryptographic key lengths).
- Basic Randomness Verification: Provides an immediate check of bit distribution (number of zeros and ones) and a simple entropy test to offer a quick indication of the randomness quality.
This project is made public for demonstration and portfolio purposes only.
All Rights Reserved.
Commercial Use, Redistribution, Modification, and Public Deployment of this code or its derivatives are NOT permitted without explicit written permission.
If you are interested in utilizing this Quantum Random Number Generation capability for commercial applications, secure key generation, or custom solutions, please contact me directly to discuss licensing, service agreements, or potential collaborations.
Contact: [Email Address - shanujansh@gmail.com]
To set up and run this project, you will need:
- Python 3.8+
- Required Python Libraries:
qiskitqiskit-aerqiskit-ibm-runtimepython-dotenv
- IBM Quantum Account: An active IBM Quantum account is necessary to obtain an API key and access their quantum processors. A free tier account provides sufficient access for demonstration and occasional high-value use.
These instructions are for setting up the environment to run the QRNG locally for personal experimentation or demonstration purposes:
- Clone the repository:
git clone https://github.com/shanujans/Quantum-Random-Number-Generator.git cd Quantum-Random-Number-Generator - Create a Virtual Environment (Highly Recommended):
python -m venv venv # On Windows: .\venv\Scripts\activate # On macOS/Linux: source venv/bin/activate
- Install Python Dependencies:
pip install qiskit qiskit-aer qiskit-ibm-runtime python-dotenv
- Configure IBM Quantum API Key:
- Retrieve your personal API Token from your IBM Quantum Experience Account page.
- Create a file named
.envin the root directory of this project (next toquantum_rng_api.py). - Add your API key to this
.envfile in the following format:IBM_API_KEY=YOUR_API_TOKEN_HERE - Crucial Security Note: The
.envfile is intentionally excluded from version control (.gitignore) to protect your sensitive API key. Do NOT commit your actual.envfile to any repository.
- Ensure your virtual environment is active:
# On Windows: .\venv\Scripts\activate # On macOS/Linux: source venv/bin/activate
- Execute the script:
python quantum_rng_api.py
- The program will prompt you to input the desired number of random bits (ranging from 8 to 256).
Below is an example of the kind of output generated by the QRNG, demonstrating its connection to IBM Quantum hardware and the resulting random values:
=== Quantum Random Number Generator ===
Enter number of bits (8-256): 12
✅ Connected to IBM Quantum Cloud
ℹ️ Using IBM Quantum instance: Quantum_rng
🔧 Selected quantum processor: ibm_sherbrooke # This may also show ibm_brisbane or another backend
🚀 Job submitted. ID: d0vaf57p51os73b2q
🔗 Monitor at: https://quantum.ibm.com/jobs/d0vaf57p51os73b2q
🎉 Quantum generation successful in 3.06s
Random bits: 100101110011
Decimal value: 2419
Quantum properties:
Bit distribution: 5 zeros, 7 ones
Entropy test: Pass
This project's advanced capabilities serve as a strong foundation for offering highly specialized, high-value quantum randomness services. My focus is on delivering unique, robust, and verifiable random data for critical applications where genuine unpredictability is paramount.
For inquiries regarding these specialized services, please refer to the "Usage & Licensing Terms" section above.