Skip to main content

High-performance, cryptographically secure hybrid PRNG library.

Project description

🎲 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:

  1. Use import random: Blazing fast, but relies on the predictably insecure Mersenne Twister algorithm. (Vulnerable)
  2. 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 random API. 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 secrets module.
  • 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.

  1. OS Entropy Injection: All engines seed from os.urandom() (the operating system's raw physical entropy pool).
  2. State Protection: Functions like getstate() and setstate() intentionally raise NotImplementedError. This prevents malicious actors from extracting the PRNG state or executing replay attacks.
  3. Entropy Stretching: By using modern stream ciphers (like ChaCha20 in Rust) and hashing algorithms (SHA-256 in Python), Hyrandom expands 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.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

hyrandom-1.0.0.tar.gz (9.5 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

hyrandom-1.0.0-cp314-cp314-win_amd64.whl (10.2 kB view details)

Uploaded CPython 3.14Windows x86-64

File details

Details for the file hyrandom-1.0.0.tar.gz.

File metadata

  • Download URL: hyrandom-1.0.0.tar.gz
  • Upload date:
  • Size: 9.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.14.0

File hashes

Hashes for hyrandom-1.0.0.tar.gz
Algorithm Hash digest
SHA256 b7336631fd929cec6de022e324621f41a8f0cbec93be0c3f3371531dcd302f77
MD5 bd11c5d156f70f08dc72603729ab6beb
BLAKE2b-256 c63caa470526751af249649063d99508717e15ffe5e85608e9bc00bba15f9c36

See more details on using hashes here.

File details

Details for the file hyrandom-1.0.0-cp314-cp314-win_amd64.whl.

File metadata

  • Download URL: hyrandom-1.0.0-cp314-cp314-win_amd64.whl
  • Upload date:
  • Size: 10.2 kB
  • Tags: CPython 3.14, Windows x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.14.0

File hashes

Hashes for hyrandom-1.0.0-cp314-cp314-win_amd64.whl
Algorithm Hash digest
SHA256 380921356ce7c745ceaacb8a87dea1bec4c7c959d3b53268cff0fb329c5651db
MD5 f1fbb9d0689b61509c87554b7d9e29c8
BLAKE2b-256 4d839d0aef0d4a6b5addc1992470caf37ca2d5e40448dc83ae827e8ed6f257c9

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page