🎲 Hyrandom
The Ultimate Cryptographically Secure PRNG for Python. Faster than random. Securer than secrets.
📊 Benchmarks
Generating 10,000,000 floats on a standard multi-core CPU.
| Library / Engine | Security | Speed (Time) | Performance Gain |
|---|---|---|---|
random (Stdlib) |
❌ Insecure | ~1.85s | Baseline |
secrets (Stdlib) |
✅ Secure | ~18.35s | 10x Slower |
hyrandom (Native) |
✅ Secure | ~2.10s | 8x Faster (vs secrets) |
hyrandom[secure] |
✅ Secure | ~0.22s | 83x Faster |
hyrandom[fast] |
❌ Insecure | ~0.09s | 200x Faster (Best for ML/AI) |
hyrandom[rust] |
✅ Secure | ~0.001s | 18,000x Faster 🚀 |
Note:
hyrandom[fast]intentionally bypasses cryptographic safety to provide raw statistical throughput for Monte Carlo simulations and machine learning.
🛑 The Problem
For decades, Python developers have been forced to make a dangerous compromise:
- Use
import random: Blazing fast, but relies on the predictably insecure Mersenne Twister algorithm. (Vulnerable) - Use
import secrets: Cryptographically secure (CSPRNG), but agonizingly slow, crippling high-throughput web servers and simulations. (Bottleneck)
🚀 The Solution: hyrandom
hyrandom eliminates the compromise. By implementing a dynamic, multi-backend architecture, it intelligently routes your randomness requests to the fastest available hardware-accelerated engine on your system—scaling from pure Python SHA-256 entropy stretching up to a hyper-optimized Rust-based ChaCha20 engine.
You get military-grade security at simulation-grade speeds.
🔥 Key Strengths
- 100% Drop-In Replacement: Fully implements the standard Python
randomAPI. Zero code refactoring required. - Zero-Friction Fallback: The library never fails. It attempts to load Rust -> falls back to Vectorized NumPy -> falls back to Pure Python Native buffering.
- Fork & Thread Safe: Built-in safeguards against PID forking vulnerabilities (a notorious issue in multi-worker servers like Gunicorn/uWSGI).
- Unprecedented Speed: Up to 18,000x faster than the standard
secretsmodule. - Developer CLI Tool: Instantly generate secure tokens or benchmark your server directly from the terminal.
⚡ Simplicity at its Core
1. Installation & Performance Tiers
hyrandom is highly modular. You only install what you need. (No Rust compiler is required for end-users when pre-compiled wheels are downloaded).
# 1. Native Tier (Zero dependencies. Best for lightweight microservices)
pip install hyrandom
# 2. Fast Tier (Maximum simulation speed via NumPy SFC64. Not for cryptography)
pip install hyrandom[fast]
# 3. Secure Tier (High-throughput vectorized cryptography via NumPy)
pip install hyrandom[secure]
# 4. Ultimate Tier (Hardware-accelerated ChaCha20 via Rust)
pip install hyrandom[rust]
# 5. Full Installation (Installs all Python dependencies and backends)
pip install hyrandom[full]
2. The 1-Line Integration
Simply swap your import statement. Every standard distribution (gauss, uniform, choice, shuffle) works flawlessly.
# Before: import random
import hyrandom as random
# Cryptographically secure, incredibly fast.
user_id = random.randint(100000, 999999)
session_token = random.token_urlsafe(64)
winning_item = random.choice(['Apple', 'Banana', 'Orange'])
# Check which backend your system is utilizing:
print(random.get_current_engine())
# Output: "Rust (ChaCha20)"
3. Command Line Interface (CLI)
hyrandom acts as a powerful system tool right out of the box.
# Generate a secure 64-byte hex token for JWTs or API Keys
$ hyrandom token --length 64 --format hex
e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855...
# Benchmark the active engine on your current hardware
$ hyrandom bench --iterations 5000000
--- hyrandom Benchmark ---
Engine: Rust (ChaCha20)
Generating 5,000,000 floats...
Time elapsed: 0.0042 seconds
Operations/sec: 1,190,476,190
🛡️ Security Posture & Architecture
hyrandom doesn't just "guess" numbers. It is engineered for enterprise-grade cryptographic operations.
- OS Entropy Injection: All engines seed from
os.urandom()(the operating system's raw physical entropy pool). - State Protection: Functions like
getstate()andsetstate()intentionally raiseNotImplementedError. This prevents malicious actors from extracting the PRNG state or executing replay attacks. - Entropy Stretching: By using modern stream ciphers (like ChaCha20 in Rust) and hashing algorithms (SHA-256 in Python),
hyrandomexpands a small, highly secure physical seed into billions of random numbers without starving the OS entropy pool.
📜 License
Released under the MIT License. Free for personal, academic, and commercial use. See the LICENSE file in the repository for full details.
Metadata
Release files for hyrandom 1.0.6
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| hyrandom-1.0.6.tar.gz | 13.6 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| hyrandom-1.0.6-cp314-cp314-win_amd64.whl | CPython 3.14 | CPython 3.14 | Windows x86-64 | Details |
Total release size: 110.2 kB
Release files / hyrandom-1.0.6.tar.gz
| Download URL | hyrandom-1.0.6.tar.gz |
|---|---|
| Size | 13.6 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
f000cada1f4d06e8d6b2fa3bee68a4c4e2c8820782b4573bee29d32fd775d320
|
|
BLAKE2b-256 checksum How to use checksums |
a928888ea9fc3c3aee2814e519b10ec525b8d5259751426270b29c18fa6827a0
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.14.0
|
Release files / hyrandom-1.0.6-cp314-cp314-win_amd64.whl
| Download URL | hyrandom-1.0.6-cp314-cp314-win_amd64.whl |
|---|---|
| Size | 96.5 kB |
| Tags | CPython 3.14 Windows x86-64 |
|
SHA-256 checksum How to use checksums |
afd2d294ab61d0052d27483f0648212d94e2259c7e0b13ded17e21d7e63a737e
|
|
BLAKE2b-256 checksum How to use checksums |
ca338716b140af7c65183346defff3875dccb132a7707ed35b2a2ec9b511d0e8
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.14.0
|