True random numbers sourced from live cryptocurrency market data
Project description
coinrandom
한국어 | English
True random numbers sourced from live cryptocurrency market data.
import coinrandom
coinrandom.random() # 0.7182818...
coinrandom.randint(1, 100) # 42
coinrandom.choice(["a", "b", "c"])
Why coinrandom?
Cryptocurrency markets trade 24/7 globally. At the tick level — individual trade prices, quantities, timestamps, and buyer/seller direction — the data is highly unpredictable. The Efficient Market Hypothesis (EMH) says no one can consistently predict short-term market movements. coinrandom uses this unpredictability as an entropy source.
Trust Model
Even with the full source code published, no one can predict the output in advance — because no one can predict the coin market.
This is an application of Kerckhoffs's principle: security depends on the unpredictability of the market, not on keeping the algorithm secret. Each value generated by Heavy/SuperHeavy comes with a RandomProof — a verifiable audit trail showing exactly which market data produced the result.
Honest limits: coinrandom provides computational security (like AES/RSA), not information-theoretic security (like Chainlink VRF). The trust model is economic, not mathematical. For cryptographic key generation, use secrets. For smart contract RNG, use Chainlink VRF.
Installation
pip install coinrandom # Light + Heavy
pip install "coinrandom[superheavy]" # + SuperHeavy (numpy, scipy)
No API keys. No configuration.
Three Tiers
| Tier | Speed | Entropy source | Proof | Use case |
|---|---|---|---|---|
| Light | ~1ms | Binance tick + Argon2 | No | High-volume generation |
| Heavy | ~2s | 3 exchanges + ETH + BTC block hash + Argon2 | Yes | Raffles, NFT mints, DAO votes |
| SuperHeavy | ~30s | Portfolio-optimized coins + Heavy pipeline (ETH + BTC) | Yes | Maximum entropy, auditable |
All tiers return the same API — drop-in replacement for Python's random module.
Usage
Function Reference
| Function | Signature | Description |
|---|---|---|
random() |
() → float |
Uniform float in [0.0, 1.0) |
uniform(a, b) |
(float, float) → float |
Uniform float in [a, b] |
randint(a, b) |
(int, int) → int |
Uniform integer in [a, b] inclusive |
choice(seq) |
(Sequence) → Any |
One random element from a sequence |
choices(seq, k) |
(Sequence, int) → list |
k elements with replacement |
sample(seq, k) |
(Sequence, int) → list |
k elements without replacement |
shuffle(seq) |
(MutableSequence) → None |
In-place shuffle |
gauss(mu, sigma) |
(float, float) → float |
Normal distribution sample |
random_with_proof() |
() → RandomProof |
Heavy / SuperHeavy only — value + audit trail |
All functions have async variants prefixed with a: arandom(), arandint(), arandom_with_proof(), etc.
Light (default)
import coinrandom
# Basic
coinrandom.random() # 0.7182818... float in [0.0, 1.0)
coinrandom.uniform(1.5, 9.5) # 6.234... float in [a, b]
coinrandom.randint(1, 6) # 4 integer in [a, b] inclusive
coinrandom.gauss(mu=0.0, sigma=1.0) # -0.312... normal distribution
# Sequences
coinrandom.choice(["rock", "paper", "scissors"]) # pick one
coinrandom.choices(range(1, 7), k=5) # roll dice 5 times (with replacement)
coinrandom.sample(range(1, 46), k=6) # lotto numbers (no duplicates)
lst = list(range(1, 11))
coinrandom.shuffle(lst) # in-place shuffle
# Practical: raffle — pick 3 winners from participants
participants = ["Alice", "Bob", "Carol", "Dave", "Eve"]
winners = coinrandom.sample(participants, k=3)
# Practical: 5% probability event
if coinrandom.random() < 0.05:
print("rare drop!")
Heavy — with proof
Each call fetches live data from 3 exchanges + ETH + BTC block hashes, then applies Argon2id.
Returns a RandomProof with a full audit trail.
from coinrandom import heavy
# Simple usage — same API as Light
val = heavy.random()
n = heavy.randint(1, 100)
# Practical: auditable raffle
participants = ["Alice", "Bob", "Carol", "Dave", "Eve"]
proof = heavy.random_with_proof()
winner = participants[int(proof.value * len(participants))]
print(winner)
print(proof.value) # 0.3571428...
print(proof.block_hashes) # {"ETH": "0xabc123...", "BTC": "000000000000..."}
print(proof.block_hashes["ETH"])
print(proof.block_hashes["BTC"])
print(proof.exchanges) # [{"exchange": "binance", "symbol": "BTCUSDT", ...}, ...]
print(proof.final_hash) # SHA-256 of the Argon2-stretched entropy
print(proof.timestamp) # "2026-05-17T09:00:00.123456"
# NFT mint order — shuffle with proof
token_ids = list(range(1, 10001))
for _ in range(len(token_ids)):
proof = heavy.random_with_proof()
# use proof.value to drive each swap step, saving proofs for audit
SuperHeavy — portfolio-optimized entropy
Runs inverse Markowitz optimization to select the least-correlated coins as entropy sources before executing the Heavy pipeline.
from coinrandom import superheavy # requires: pip install "coinrandom[superheavy]"
val = superheavy.random()
proof = superheavy.random_with_proof()
print(proof.value)
print(proof.selected_symbols) # coins selected by inverse portfolio optimization
print(proof.correlation_matrix) # correlation matrix of candidates
print(proof.optimization_result) # scipy SLSQP result
print(proof.block_hashes) # {"ETH": "...", "BTC": "..."}
print(proof.final_hash)
Saving proof as JSON
RandomProof and SuperProof are plain dataclasses — serialize with the standard library:
import dataclasses, json
proof = heavy.random_with_proof()
with open("proof.json", "w") as f:
json.dump(dataclasses.asdict(proof), f, indent=2)
Async API
All functions have async variants prefixed with a.
import asyncio
import coinrandom
from coinrandom import heavy, superheavy # superheavy requires [superheavy] extra
async def main():
# Light
val = await coinrandom.arandom()
n = await coinrandom.arandint(1, 100)
c = await coinrandom.achoice(["a", "b", "c"])
lst = [1, 2, 3]
await coinrandom.ashuffle(lst)
# Heavy
val = await heavy.arandom()
proof = await heavy.arandom_with_proof()
print(proof.block_hashes)
# SuperHeavy
val = await superheavy.arandom()
proof = await superheavy.arandom_with_proof()
print(proof.selected_symbols)
asyncio.run(main())
Async methods offload blocking I/O to a thread pool via asyncio.run_in_executor — no new dependencies.
Design Principles
- No API keys — works out of the box with
pip install - Uniform API — every tier exposes the same functions as
random - No Mersenne Twister — custom HashDRBG (SHA-512 counter-based) seeded from coin market data and OS hardware entropy
- Open-source safe — Kerckhoffs's principle: publishing the algorithm doesn't compromise security
- Intentionally heavy — Heavy/SuperHeavy: each call runs the full entropy pipeline. "Slow = costly to manipulate."
Internals
coinrandom/
├── __init__.py # Light tier as default API
├── core.py # fetch_binance_entropy, mix_entropy
├── proof.py # RandomProof, SuperProof dataclasses
├── light/ # HashDRBG + Argon2 (t=1, m=8MB) reseed cache
├── heavy/ # 3 exchanges parallel + ETH block hash + Argon2 (t=4, m=64MB)
└── superheavy/ # Inverse portfolio optimization → Heavy pipeline
HashDRBG
Custom SHA-512 counter-based DRBG. No import random anywhere in the codebase.
# Simplified
state = argon2(mix_entropy(coin_data, os.urandom(32)))
output = sha512(state + counter) # per call
Manipulation resistance
Heavy mode requires simultaneously moving 32+ coins across Binance, Upbit, and Coinbase in the exact direction needed — estimated cost: billions of dollars. SuperHeavy additionally hides the target coins until optimization runs.
License
MIT
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 coinrandom-1.0.1.tar.gz.
File metadata
- Download URL: coinrandom-1.0.1.tar.gz
- Upload date:
- Size: 15.9 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
f844178e5575d7a1fc18b8d53dbd7476ae064fd373a10f92034c455c0240aa55
|
|
| MD5 |
4fcba984f1076946013aec277181005b
|
|
| BLAKE2b-256 |
4bd8f756fc8b4341304dd1847f8e0b2c39acfdfd110d92254b6c2c9f052f51d2
|
Provenance
The following attestation bundles were made for coinrandom-1.0.1.tar.gz:
Publisher:
cd.yml on LETUED/coinrandom
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
coinrandom-1.0.1.tar.gz -
Subject digest:
f844178e5575d7a1fc18b8d53dbd7476ae064fd373a10f92034c455c0240aa55 - Sigstore transparency entry: 1566745252
- Sigstore integration time:
-
Permalink:
LETUED/coinrandom@95fcfe36dcda27e2d957a971de25bb2d19aaddf8 -
Branch / Tag:
refs/tags/v1.0.1 - Owner: https://github.com/LETUED
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
cd.yml@95fcfe36dcda27e2d957a971de25bb2d19aaddf8 -
Trigger Event:
push
-
Statement type:
File details
Details for the file coinrandom-1.0.1-py3-none-any.whl.
File metadata
- Download URL: coinrandom-1.0.1-py3-none-any.whl
- Upload date:
- Size: 16.6 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
e46aecc4fac096e795e4e2010e31463a34af2bb9065df341ca0897f26eede1ee
|
|
| MD5 |
7553ff159a1194671bdc9f1b680a377f
|
|
| BLAKE2b-256 |
d61e1d0028f40781bd215142ca2f22bd1741d2b701df8df246af759056405848
|
Provenance
The following attestation bundles were made for coinrandom-1.0.1-py3-none-any.whl:
Publisher:
cd.yml on LETUED/coinrandom
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
coinrandom-1.0.1-py3-none-any.whl -
Subject digest:
e46aecc4fac096e795e4e2010e31463a34af2bb9065df341ca0897f26eede1ee - Sigstore transparency entry: 1566745269
- Sigstore integration time:
-
Permalink:
LETUED/coinrandom@95fcfe36dcda27e2d957a971de25bb2d19aaddf8 -
Branch / Tag:
refs/tags/v1.0.1 - Owner: https://github.com/LETUED
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
cd.yml@95fcfe36dcda27e2d957a971de25bb2d19aaddf8 -
Trigger Event:
push
-
Statement type: