Skip to main content

MultiRandom 🎲

A comprehensive library for exploring and generating randomness across the spectrum—from true physical entropy to mathematical pseudo-randomness and everything in between.

🌟 Overview

MultiRandom is designed for developers, researchers, and hobbyists who want to understand high-quality randomness. It provides tools to fetch random data from quantum sources, physical human interaction, and modern mathematical algorithms.


🏗 Project Structure

multirandom/
└── src/
    └── multirandom/
        ├── trng/               # True / Physical Entropy
        │   ├── rand_via_clicks.py        # Human-in-the-loop entropy
        │   ├── rand_using_online_api.py  # Quantum & Hardware APIs (ANU QRNG, Roll-API)
        │   ├── rand_using_real_random.py # Microphone entropy (real-random)
        │   └── weather_rand.py           # [Coming Soon] Weather-based entropy
        ├── csprng/             # Cryptographically Strong Randomness
        │   ├── secure_rand.py            # OS CSPRNGs, NIST DRBGs, Fortuna/Yarrow, ISAAC
        │   ├── sha_rand.py               # MD5, SHA-1/2/3, BLAKE2, SHAKE PRNGs
        │   └── original_random.py        # Wrapper for Python's built-in random
        └── prng_unsecure/      # Mathematical Randomness (UNSECURE PRNGs)
            ├── xor_shift.py              # XorShift & Xoshiro Family
            ├── rand_using_virt_lcg.py    # Linear Congruential Generators (LCGs)
            └── flash_rand_and_reverse.py # [Coming Soon] Specialized PRNGs

🛠 Features & Usage

1. Human-in-the-loop Entropy (trng)

Uses pyautogui and Windows API to capture sub-microsecond timing jitter and spatial coordinates from physical mouse clicks.

from multirandom.trng.rand_via_clicks import RealRandomUsingBetweenMixedClicks

# Requires a sequence of Left -> Right -> Middle clicks to seed
gen = RealRandomUsingBetweenMixedClicks()
print(gen.random())

2. Physical & Hardware APIs (trng)

Fetch "True" randomness from remote physical processes.

  • Australian National University (ANU): Quantum vacuum noise via QRNG.
  • Random.org: Atmospheric noise.
  • Roll-API: Physical dice rolling hardware.
  • Microphone: Ambient audio noise via real-random (optional extra).
  • Weather Entropy: (In development) Fetching randomness from real-time weather stations.
from multirandom.trng.rand_using_real_random import MicrophoneRandom

gen = MicrophoneRandom()   # captures ~1-2 s of ambient audio
print(gen.random())
gen.reseed()               # capture fresh entropy on demand

3. Bit-Shift Generators (prng_unsecure)

Implementations of the most popular mathematical generators used in modern systems.

  • Original XorShift: Xorshift32 / Xorshift64 / Xorshift128, each with reverse_roll() to demonstrate mathematical reversibility. Xorshift32 also inverts via increasing increments (reverse_roll_increments()), shift doubling (reverse_roll_doubling()) and GF(2) matrix inversion (reverse_roll_matrix()) — all equivalent.
  • Scrambled Variants: Xorwow (CUDA), Xorshift* & Xorshift1024* (Vigna), Xorshift+ (V8/Webkit).
  • Modern Xoshiro: Xoshiro128 +/++/**, Xoshiro256 +/++/**, Xoroshiro64 */**, Xoroshiro128 +/++/** (Minecraft Java 1.18+ uses ++).

Run python -m multirandom.prng_unsecure.xor_shift to check every generator against reference vectors.

4. Mathematical LCGs (prng_unsecure)

Classic Linear Congruential Generators with customizable shift parameters. Includes reverse_roll() methods to demonstrate the insecurity of simple modular arithmetic.

5. Hash-based Generators (csprng)

Counter-mode hash DRBGs: H(seed || counter) drives the full random.Random API.

  • SHA-2: SHA-224, SHA-256, SHA-384, SHA-512
  • SHA-3: SHA3-224, SHA3-256, SHA3-384, SHA3-512
  • Extendable output: SHAKE-128, SHAKE-256
  • BLAKE2: BLAKE2b, BLAKE2s
  • Legacy (educational only): MD5, SHA-1
from multirandom.csprng.sha_rand import BLAKE2bRandom

gen = BLAKE2bRandom("my seed")
print(gen.randbytes(16).hex(), gen.random(), gen.choice(["a", "b"]))

6. Cryptographically Strong Generators (csprng/secure_rand)

The ones to actually guard things with, plus deliberately broken ones that teach.

OS-level CSPRNGs (live entropy, behave like random.SystemRandom — seeding is a no-op and state cannot be restored):

Class Source
SecretsRandom the secrets module (+ token_bytes / token_hex / token_urlsafe)
OSURandom plain os.urandom
GetRandomRandom Linux getrandom(2)
BCryptGenRandomRandom Windows BCryptGenRandom
SecRandomCopyBytesRandom Apple SecRandomCopyBytes

The ctypes ones fall back to os.urandom (the same kernel entropy pool) when the native API is not reachable on the running platform.

NIST SP 800-90A DRBGs (seedable, deterministic from an explicit seed, full random.Random API with getrandbits / randbytes / choice / shuffle ...):

  • CTR_DRBG – AES-128 with the §10.5.1 derivation function
  • HMAC_DRBG – HMAC-SHA-256
  • Hash_DRBG – SHA-256 with Hash_df (440-bit state)
  • Dual_EC_DRBG — deliberately backdoored, kept as a teaching exhibit

Stream / accumulator designs: ChaCha20DRBG, Salsa20DRBG (counter-mode DRBGs on the two classic stream ciphers), FortunaRandom (32 seed pools + AES-256-CTR, rekey every 65536 blocks, add_entropy(data, pool)) and its legacy predecessor YarrowRandom (fast/slow pools, AES-192-CTR), plus ISAACRandom (Bob Jenkins' ISAAC, validated against his reference vectors).

from multirandom.csprng.secure_rand import SecretsRandom, CTR_DRBG, Dual_EC_DRBG

gen = SecretsRandom()
print(gen.token_hex(32))            # live kernel entropy

drbg = CTR_DRBG("my secret seed")   # deterministic; also reseeds:
drbg.reseed(b"fresh entropy")
print(drbg.randbytes(32).hex())

The backdoor, live

Dual_EC_DRBG reproduces the withdrawn NIST design: outputs are the high bits of x(s*P) on NIST P-256, the state advances to x(s*Q) — and whoever built Q = d*P knows d. .reveal(one_block) brute-forces the truncated bits and recovers the next internal state with the secret multiplier:

victim = Dual_EC_DRBG("demo victim key", truncate_bits=8)
first, second, third = victim.randbytes(31), victim.randbytes(31), victim.randbytes(31)

s1 = victim.reveal(first, known_next=second)   # Shumow–Ferguson attack
predictor = Dual_EC_DRBG.__new__(Dual_EC_DRBG)
predictor.truncate_bits = 8
predictor._s = s1
assert predictor.randbytes(31) == second       # predicted the future
assert predictor.randbytes(31) == third        # ...and the block after it

The default truncate_bits=16 matches the standard (recovering a state costs about 2**15 curve multiplications — instant in C, slow in pure Python); the module ships with this demo running in its own self-checks at truncate_bits=8. It warns on first use. Never use it for real randomness.

# Run its assert battery: python -m multirandom.csprng.secure_rand

The global unsecure-prng warning switch

Everything in prng_unsecure/ and the backdoored Dual_EC_DRBG warns the first time it is constructed. One package-root variable controls those warnings:

import multirandom

multirandom.ignore_unsecure_prng_warning_do_not_set_to_true_unless_you_know_how_risky_it_is = True
  • False (the default): every unsecure-PRNG warning goes to the console.
  • True: the warnings are ignored (not printed) — risk is all yours.

🚀 Installation & Setup

Requirements

  • Python 3.9+
  • Dependencies listed in requirements.txt (e.g., pyautogui, aiohttp)

Installation

pip install -r requirements.txt

# Optional: microphone entropy source (adds numpy + sounddevice)
pip install "multirandom[microphone]"

Usage

from multirandom.prng_unsecure.xor_shift import Xorshift32

# Create a 32-bit XorShift generator
gen = Xorshift32(seed=12345)
print(gen.roll())

📺 Educational Resources

This project focuses on the limits of computer-generated randomness. For more context, check out:


📜 License

Licensed under the Apache License 2.0.

Metadata

Release files for multirandom 0.0.6

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for multirandom 0.0.6
File Size Uploaded Provenance Actions
multirandom-0.0.6.tar.gz 43.5 kB Without provenance Details for multirandom-0.0.6.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for multirandom 0.0.6
File Interpreter ABI Platform Actions
multirandom-0.0.6-py3-none-any.whl Python 3 none any Details for multirandom-0.0.6-py3-none-any.whl

Total release size: 87.1 kB

Release files / multirandom-0.0.6.tar.gz

Download URL multirandom-0.0.6.tar.gz
Size 43.5 kB
Tags Source
SHA-256 checksum
How to use checksums
f937b7bc7b176f9d08a1cb1cf6e17b106d1a526e9299ea9a913cbd8c626953c2
BLAKE2b-256 checksum
How to use checksums
8fefd56469463389da788ee6b8bbc3a105a171eb94c16a97bbe8dd84326a153c
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.14.9

Release files / multirandom-0.0.6-py3-none-any.whl

Download URL multirandom-0.0.6-py3-none-any.whl
Size 43.7 kB
Tags Python 3
SHA-256 checksum
How to use checksums
a694881c7806231a2378881bd44eac3196f01700fdeca96cf70bacee38e47dc5
BLAKE2b-256 checksum
How to use checksums
53472256c57f7b9a4db3d8211e55e92c3fcc4f364f75e86b06666d7b203d3ba8
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.14.9

Security for multirandom 0.0.6

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page