A service providing true quantum random numbers from ANU QRNG and other sources
Project description
Quantum Randomness Service
A comprehensive service that provides true quantum random numbers from multiple sources including ANU's Quantum Random Number Generator (QRNG) and configurable custom sources.
Features
- ๐ True Quantum Randomness - Direct from quantum sources
- ๐ High-Performance API - FastAPI backend with async support
- ๐ฆ Python Library - Easy-to-use client library
- ๐พ Smart Caching - Redis-based caching for performance
- ๐ Real-time Streaming - WebSocket support for live random numbers
- ๐ Entropy Visualization - Interactive web interface
- ๐ง Multiple Sources - ANU QRNG + configurable sources
- ๐ก๏ธ Cryptographic Quality - Suitable for security applications
Installation
Option 1: Install as a Package (Recommended)
# Install the package
pip install quantum-randomness-service
# Or install with Redis support
pip install quantum-randomness-service[redis]
# Or install with development dependencies
pip install quantum-randomness-service[dev]
Option 2: Install from Source
# Clone the repository
git clone https://github.com/yourusername/quantum-randomness-service.git
cd quantum-randomness-service
# Install dependencies
pip install -r requirements.txt
# Install the package in development mode
pip install -e .
Quick Start
Run the Service
# Method 1: Using the installed command
quantum-randomness-service
# Method 2: Using the short command
qrandom
# Method 3: Using Python directly
python -m app.main
# Method 4: Using uvicorn
uvicorn app.main:app --reload
Use the Python Library
from qrandom import QuantumRandom, get_random, get_random_batch
# Quick usage with convenience functions
random_number = get_random()
numbers = get_random_batch(10)
# Full client usage
qr = QuantumRandom()
# Synchronous methods
result = qr.get_random_sync()
print(f"Random number: {result['random_number']}")
print(f"Source: {result['source']}")
# Asynchronous methods
import asyncio
async def main():
result = await qr.get_random()
print(f"Random number: {result['random_number']}")
asyncio.run(main())
# Context manager usage
with QuantumRandom() as client:
numbers = client.get_random_numbers(5)
print(f"Numbers: {numbers}")
API Endpoints
GET /random- Get a single random numberGET /random/batch?count=100- Get multiple random numbersGET /random/stream- WebSocket stream of random numbersGET /stats- Service statistics and entropy metricsGET /visualize- Interactive entropy visualization
Architecture
โโโโโโโโโโโโโโโโโโโ โโโโโโโโโโโโโโโโโโโ โโโโโโโโโโโโโโโโโโโ
โ ANU QRNG โ โ Custom QRNG โ โ Cache Layer โ
โ (Primary) โ โ (Fallback) โ โ (Redis) โ
โโโโโโโโโโโโโโโโโโโ โโโโโโโโโโโโโโโโโโโ โโโโโโโโโโโโโโโโโโโ
โ โ โ
โโโโโโโโโโโโโโโโโโโโโโโโโผโโโโโโโโโโโโโโโโโโโโโโโโ
โ
โโโโโโโโโโโโโโโโโโโ
โ API Service โ
โ (FastAPI) โ
โโโโโโโโโโโโโโโโโโโ
โ
โโโโโโโโโโโโโโโโโโโโโโโโโผโโโโโโโโโโโโโโโโโโโโโโโโ
โ โ โ
โโโโโโโโโโโโโโโโโโโ โโโโโโโโโโโโโโโโโโโ โโโโโโโโโโโโโโโโโโโ
โ Python Client โ โ Web Interface โ โ WebSocket API โ
โ Library โ โ (Visualization)โ โ (Streaming) โ
โโโโโโโโโโโโโโโโโโโ โโโโโโโโโโโโโโโโโโโ โโโโโโโโโโโโโโโโโโโ
Use Cases
- Cryptography: Generate cryptographic keys and nonces
- Simulations: Monte Carlo methods, scientific simulations
- Gaming: Fair random number generation
- Research: Quantum computing and randomness studies
- Security: True randomness for security applications
Configuration
Create a .env file:
ANU_API_URL=https://qrng.anu.edu.au/API/jsonI.php
CACHE_TTL=300
REDIS_URL=redis://localhost:6379
CUSTOM_QRNG_URL=your-custom-qrng-url
Examples
Basic Usage
from qrandom import get_random, get_random_batch
# Get a single random number
number = get_random()
print(f"Random number: {number}")
# Get multiple random numbers
numbers = get_random_batch(5)
print(f"Random numbers: {numbers}")
Advanced Usage
from qrandom import QuantumRandom
import asyncio
async def main():
client = QuantumRandom()
# Get random number with metadata
result = await client.get_random()
print(f"Number: {result['random_number']}")
print(f"Source: {result['source']}")
print(f"Entropy: {result['entropy_score']}")
# Get service statistics
stats = await client.get_stats()
print(f"Total requests: {stats['total_requests']}")
print(f"Cache hit rate: {stats['cache_hit_rate']}%")
await client.close()
asyncio.run(main())
Error Handling
from qrandom import QuantumRandom
try:
client = QuantumRandom("http://localhost:8000")
result = client.get_random_sync()
print(f"Success: {result}")
except Exception as e:
print(f"Error: {e}")
Contributing
- Fork the repository
- Create a feature branch
- Make your changes
- Add tests
- Submit a pull request
License
MIT License - see LICENSE file for details.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file quantum_randomness_service-1.0.0.tar.gz.
File metadata
- Download URL: quantum_randomness_service-1.0.0.tar.gz
- Upload date:
- Size: 57.8 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.12.3
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
29e822a8de4abb5e297eb9be0f6a2dd92551882a12c96f3a43e3260385dc7ec1
|
|
| MD5 |
a71c7c46ace19b3379c5965572a89173
|
|
| BLAKE2b-256 |
ffde407c32ff4a39de08f9b7b360d230d85b19c1ce6cc467c4a1f1c5cfdeadaf
|
File details
Details for the file quantum_randomness_service-1.0.0-py3-none-any.whl.
File metadata
- Download URL: quantum_randomness_service-1.0.0-py3-none-any.whl
- Upload date:
- Size: 48.4 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.12.3
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
28c7211952fb941be87aff5827b69c5c81eec82188cad3ee03d9e5f8b0a1b3ab
|
|
| MD5 |
eb58881516466490ccc8d2ec2c32a3d5
|
|
| BLAKE2b-256 |
4bf50fee71de59b64e8758310cc0b83eff68229e333881db95b7ec37fe41e134
|