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. Every value 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 # Standard
pip install "coinrandom[heavy]" # + Heavy (numpy, scipy)
No API keys. No configuration.
Two Tiers
| Tier | Speed | Entropy source | Proof | Use case |
|---|---|---|---|---|
| Standard (default) | ~2s | 3 exchanges + ETH/BTC/SOL block data + Argon2id | Yes | Raffles, NFT mints, DAO votes |
| Heavy | ~30s | Portfolio-optimized coins + Standard pipeline | Yes | Maximum entropy, auditable |
Both tiers run the full entropy pipeline on every call and return the same API — a 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 |
Value + audit trail (Heavy returns HeavyProof) |
All functions have async variants prefixed with a: arandom(), arandint(), arandom_with_proof(), etc.
Standard (default)
Each call fetches live data from 3 exchanges (Binance, Upbit, Coinbase) + ETH/BTC/SOL block data, then applies Argon2id (t=4, m=64MB). Returns a RandomProof with a full audit trail.
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: auditable raffle — pick a winner from participants
participants = ["Alice", "Bob", "Carol", "Dave", "Eve"]
proof = coinrandom.random_with_proof()
winner = participants[int(proof.value * len(participants))]
print(winner)
print(proof.value) # 0.3571428...
print(proof.block_hashes) # {"ETH": "0xabc123...", "BTC": "000...", "SOL": "..."}
print(proof.exchanges) # [{"exchange": "binance", "symbol": "BTCUSDT", ...}, ...]
print(proof.symbols) # symbols used as entropy
print(proof.final_hash) # SHA-256 of the Argon2-stretched entropy
print(proof.timestamp) # "2026-06-13T09:00:00.123456+00:00"
Heavy — portfolio-optimized entropy
Runs inverse Markowitz optimization to select the least-correlated coins as entropy sources before executing the Standard pipeline. Requires the [heavy] extra.
from coinrandom import heavy # requires: pip install "coinrandom[heavy]"
val = heavy.random()
proof = heavy.random_with_proof()
print(proof.value)
print(proof.selected_symbols) # coins selected by inverse portfolio optimization
print(proof.candidate_count) # number of candidate coins analyzed
print(proof.correlation_matrix) # correlation matrix of candidates
print(proof.optimization_result) # scipy SLSQP result
print(proof.block_hashes) # {"ETH": "...", "BTC": "...", "SOL": "..."}
print(proof.final_hash)
# Practical: NFT mint order — save proofs so anyone can verify the shuffle
token_ids = list(range(1, 10001))
heavy.shuffle(token_ids)
Saving proof as JSON
RandomProof and HeavyProof are plain dataclasses — serialize with the standard library:
import dataclasses, json
import coinrandom
proof = coinrandom.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 # heavy requires the [heavy] extra
async def main():
# Standard
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)
proof = await coinrandom.arandom_with_proof()
print(proof.block_hashes)
# Heavy
val = await heavy.arandom()
proof = await heavy.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 — each call runs the full entropy pipeline. "Slow = costly to manipulate."
Internals
coinrandom/
├── __init__.py # Standard tier as default API
├── core.py # mix_entropy, bytes_to_float
├── proof.py # RandomProof, HeavyProof dataclasses
├── chains/ # blockchain entropy sources (eth, btc, sol)
├── standard/ # 3 exchanges + ETH/BTC/SOL + Argon2 (t=4, m=64MB)
└── heavy/ # inverse portfolio optimization → Standard 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
Manipulating Standard mode requires simultaneously moving multiple coins across Binance, Upbit, and Coinbase in the exact direction needed while also controlling ETH/BTC/SOL blocks — estimated cost: billions of dollars. Heavy 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-2.0.0.tar.gz.
File metadata
- Download URL: coinrandom-2.0.0.tar.gz
- Upload date:
- Size: 15.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
4fd9b45ac7479458d482b2b0e5f22ed00b1310b90780838c95e6c5202aa5cb68
|
|
| MD5 |
5c0251d93420fb5b2d701bc63ce078f2
|
|
| BLAKE2b-256 |
b75c6904c030f6ef501357b3a148a55e198b0cf427aae7b8b0d7471350cded20
|
Provenance
The following attestation bundles were made for coinrandom-2.0.0.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-2.0.0.tar.gz -
Subject digest:
4fd9b45ac7479458d482b2b0e5f22ed00b1310b90780838c95e6c5202aa5cb68 - Sigstore transparency entry: 1808262283
- Sigstore integration time:
-
Permalink:
LETUED/coinrandom@91e2525caceb9a2c383401bf187b4683d2123604 -
Branch / Tag:
refs/tags/v2.0.0 - Owner: https://github.com/LETUED
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
cd.yml@91e2525caceb9a2c383401bf187b4683d2123604 -
Trigger Event:
push
-
Statement type:
File details
Details for the file coinrandom-2.0.0-py3-none-any.whl.
File metadata
- Download URL: coinrandom-2.0.0-py3-none-any.whl
- Upload date:
- Size: 16.3 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 |
335685ab663c80727a4700249f6b1a531d99ab0efb3c5af69b67b1df8b09fec4
|
|
| MD5 |
8ab79647a80cfe9d47e8fccdc523d73e
|
|
| BLAKE2b-256 |
2fb43f0484447793c61e0223e91e8c5bdf3707004dea986412bcf59eeb75484a
|
Provenance
The following attestation bundles were made for coinrandom-2.0.0-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-2.0.0-py3-none-any.whl -
Subject digest:
335685ab663c80727a4700249f6b1a531d99ab0efb3c5af69b67b1df8b09fec4 - Sigstore transparency entry: 1808262317
- Sigstore integration time:
-
Permalink:
LETUED/coinrandom@91e2525caceb9a2c383401bf187b4683d2123604 -
Branch / Tag:
refs/tags/v2.0.0 - Owner: https://github.com/LETUED
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
cd.yml@91e2525caceb9a2c383401bf187b4683d2123604 -
Trigger Event:
push
-
Statement type: