Skip to main content

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 block hash + Argon2 Yes Raffles, NFT mints, DAO votes
SuperHeavy ~30s Portfolio-optimized coins + Heavy pipeline Yes Maximum entropy, auditable

All tiers return the same API — drop-in replacement for Python's random module.


Usage

Light (default)

import coinrandom

coinrandom.random()              # float in [0.0, 1.0)
coinrandom.uniform(1.5, 9.5)
coinrandom.randint(1, 100)
coinrandom.choice(["a", "b", "c"])
coinrandom.choices(["a", "b", "c"], k=5)
coinrandom.sample(range(100), k=10)

lst = [1, 2, 3, 4, 5]
coinrandom.shuffle(lst)

coinrandom.gauss(mu=0.0, sigma=1.0)

Heavy — with proof

from coinrandom.heavy import HeavyEngine

engine = HeavyEngine()
value, proof = engine.random_with_proof()

print(value)               # 0.3571428...
print(proof.exchanges)     # [{"name": "binance", "symbols": [...], ...}, ...]
print(proof.block_hash)    # "0xabc123..."
print(proof.final_hash)    # SHA-512 of the combined entropy

SuperHeavy — portfolio-optimized entropy

from coinrandom.superheavy import SuperHeavyEngine

engine = SuperHeavyEngine()
value, proof = engine.random_with_proof()

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

SuperHeavy runs inverse Markowitz portfolio optimization to select the least-correlated coins as entropy sources — maximizing entropy diversity.


Design Principles

  1. No API keys — works out of the box with pip install
  2. Uniform API — every tier exposes the same functions as random
  3. No stdlib random — custom HashDRBG (SHA-512 counter-based), Mersenne Twister not used anywhere
  4. Open-source safe — Kerckhoffs's principle: publishing the algorithm doesn't compromise security
  5. 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.


Versioning

This project follows Semantic Versioning:

  • PATCH — bug fixes, internal improvements
  • MINOR — new features, backward-compatible
  • MAJOR — stable API declaration or breaking changes

Current status: 0.x (API stabilizing, not yet guaranteed stable)


License

MIT

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

coinrandom-0.1.1.tar.gz (12.8 kB view details)

Uploaded Source

Built Distribution

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

coinrandom-0.1.1-py3-none-any.whl (14.4 kB view details)

Uploaded Python 3

File details

Details for the file coinrandom-0.1.1.tar.gz.

File metadata

  • Download URL: coinrandom-0.1.1.tar.gz
  • Upload date:
  • Size: 12.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for coinrandom-0.1.1.tar.gz
Algorithm Hash digest
SHA256 b105fbafcb2c1d67d50570624c3bbcffbb66f975fc2dd6aee3a0e55417be4138
MD5 57785d8112e912a4f04e203ff24fa57d
BLAKE2b-256 d19e1afe8565a9e8b7c085fc78d0a593111929ca6c96a3ba277cc33800544bf6

See more details on using hashes here.

Provenance

The following attestation bundles were made for coinrandom-0.1.1.tar.gz:

Publisher: cd.yml on LETUED/coinrandom

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file coinrandom-0.1.1-py3-none-any.whl.

File metadata

  • Download URL: coinrandom-0.1.1-py3-none-any.whl
  • Upload date:
  • Size: 14.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for coinrandom-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 73e666ebee624d5b4c3f4920d9eec5cc1b84831bfd3adb508b00bbd05d929cad
MD5 0ca07d90dab0aba4d925f7dd686c9901
BLAKE2b-256 99f708e8e3e0d7db90ba618831ebb24efb7607e4cafa0dc6f8c54fef506e9e36

See more details on using hashes here.

Provenance

The following attestation bundles were made for coinrandom-0.1.1-py3-none-any.whl:

Publisher: cd.yml on LETUED/coinrandom

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

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