QRNG is a Python module that leverages quantum computing to generate random numbers. This module uses Qiskit to interface with quantum simulators or quantum computers, providing various functions to generate random integers, floats, ASCII characters, and strings.
Note, due to current limitations of quantum, running this module on a real quantum computer will be slower than a classical computer. However, this module is intended to be used for educational purposes, and to demonstrate the potential of quantum computing. For reference, a single random integer between 0 and 100 takes approximately 36 minutes to generate on a real quantum computer due to queue times.
- Generate random integers within a specified range.
- Generate random floating-point numbers with specified precision.
- Generate random ASCII characters and strings.
- Batch generation for all types of random values.
- Option to choose between different quantum backends, including simulators and real quantum hardware.
Make sure you also have Qiskit installed:
pip install qiskit
Import the QRNG
class from the qrng
module and create an instance. You can specify the backend used for quantum computations.
from qrng import QRNG
# Initialize the QRNG instance
instance = QRNG(backend="qasm_simulator")
# Generate a random integer between 0 and 100
random_number = instance.integer_between(0, 100, do_prints=True, do_plots=True)
print("Random number:", random_number)
# Generate a batch of 100 random integers between 5 and 100
batch = instance.integer_batch(5, 100, 100)
print("Batch:", batch)
# Generate a random float between 0.0 and 1.0 with 4 decimal places
random_float = instance.float_between(0.0, 1.0, 4)
print("Random float:", random_float)
# Generate a random ASCII character, including uppercase
random_char = instance.ascii_random(include_uppercase=True)
print("Random character:", random_char)
# Generate a random string of length 3, including uppercase
random_string = instance.string_random(3, include_uppercase=True)
print("Random string:", random_string)
For more information, please refer to the documentation.
Pull requests are welcome. For major changes, please open an issue first to discuss what you would like to change.