Client library for unbiased random integers backed by Geiger counter decay timing.
Project description
Nuclear Random
Experimental Python random integers backed by Geiger counter decay timing.
pip install nuclear-random
from nuclear_random import choice, nuclear_random, randint, random_bytes, service_status
print(nuclear_random(100)) # 0..100 inclusive
print(nuclear_random(10_000)) # 0..10000 inclusive
print(randint(10, 20)) # 10..20 inclusive
print(random_bytes(16).hex()) # 16 extracted bytes from the entropy pool
print(choice(["red", "green", "blue"]))
status = service_status()
print(status.pool_size_bytes, status.estimated_cpm)
The public service uses a slow physical source. Calls can wait for fresh extracted bits when the pool is empty.
How It Works
The public API consumes extracted bits from an ESP32-C3 connected to a Geiger counter on GPIO 6. Each click sends the time since the previous click. The server takes a small number of raw timing bits and runs them through a Von Neumann debiasing extractor before storing full bytes in Redis.
For any request nuclear_random(max_value), the API reads max_value.bit_length() extracted bits and returns the candidate only if it is <= max_value. Candidates above the requested maximum are rejected and the API reads the next bits.
This rejection-sampling step avoids modulo bias.
Client API
from nuclear_random import choice, nuclear_random, randint, random_bytes, service_status
nuclear_random(max_value)returns an integer in0..max_value.randint(min_value, max_value)returns an integer inmin_value..max_value.choice(items)returns one item from a non-empty sequence by drawing a QRNG-backed index.random_bytes(length)returns extracted bytes from the entropy pool. This is slow on the public service.service_status()returns pool size, click rate, and extractor counters.
Configuration
By default the client uses:
https://nuclear-api.datanode.live
Override it while testing:
export NUCLEAR_RANDOM_API_URL=http://127.0.0.1:19000
or per call:
nuclear_random(131, api_url="http://127.0.0.1:19000")
Server
The server stack is Docker-only and includes:
- FastAPI API
- static public website
- Redis extracted entropy byte pool
- InfluxDB telemetry
- Wi-Fi ingest endpoint for the ESP32-C3
- USB serial monitor for diagnostics
- status metrics for the future website
- Redis-backed public API rate limiting
cp server/.env.example server/.env
docker compose -p nuclear-random --project-directory server up -d redis influxdb api site
docker compose -p nuclear-random --project-directory server --profile collector up -d collector
See docs/architecture.md, docs/deployment.md, and docs/hardware.md. See docs/publishing.md for PyPI release steps.
The ESP32-C3 firmware posts click events to https://nuclear-api.datanode.live/v1/entropy/click. Its INGEST_TOKEN must match the server INGEST_TOKEN in /home/server/nuclear_random/server/.env. It should still be built with CDCOnBoot=cdc so the USB serial debug stream is visible on /dev/ttyACM0.
Useful API endpoints:
GET /healthz
GET /v1/status
GET /v1/clicks/timeline
GET /v1/random/int?max=100
GET /v1/random/bytes?length=16
POST /v1/entropy/click
The public website is intended for https://random.datanode.live.
Status
This project is alpha-quality. It uses radioactive decay timing with Von Neumann debiasing, but it has not been cryptographically certified. Throughput is intentionally low because the service does not synthesize extra bytes from each click.
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
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 nuclear_random-0.2.2.tar.gz.
File metadata
- Download URL: nuclear_random-0.2.2.tar.gz
- Upload date:
- Size: 28.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 |
b57e3aa68cbea2abca869be7cb81bc0b19ccdca2a85ceda1ff3e08d6b63d0e36
|
|
| MD5 |
961ad9ba5df80a9c0693a89432a67c5c
|
|
| BLAKE2b-256 |
b5fe45ecd04e182d66d1cb79976a371a5aac76a10642fb3d897f2d71aa1a3996
|
Provenance
The following attestation bundles were made for nuclear_random-0.2.2.tar.gz:
Publisher:
publish.yml on TimofeySukh/nuclear-random
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
nuclear_random-0.2.2.tar.gz -
Subject digest:
b57e3aa68cbea2abca869be7cb81bc0b19ccdca2a85ceda1ff3e08d6b63d0e36 - Sigstore transparency entry: 1429138065
- Sigstore integration time:
-
Permalink:
TimofeySukh/nuclear-random@1b2819383bb1220e188ce1e12ab8eeb080929fe1 -
Branch / Tag:
refs/tags/v0.2.2 - Owner: https://github.com/TimofeySukh
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@1b2819383bb1220e188ce1e12ab8eeb080929fe1 -
Trigger Event:
push
-
Statement type:
File details
Details for the file nuclear_random-0.2.2-py3-none-any.whl.
File metadata
- Download URL: nuclear_random-0.2.2-py3-none-any.whl
- Upload date:
- Size: 6.5 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 |
bebe106babb8ba9bb80624fc3364446c78c561efb726950e21cfd758ea0c7ab3
|
|
| MD5 |
309e6493e0b7cc856ea73710201e1d5e
|
|
| BLAKE2b-256 |
1e140cd32d2fa58b8dd3454246272e2fd4f9dce786ebea28e0e368c5dc08ad6c
|
Provenance
The following attestation bundles were made for nuclear_random-0.2.2-py3-none-any.whl:
Publisher:
publish.yml on TimofeySukh/nuclear-random
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
nuclear_random-0.2.2-py3-none-any.whl -
Subject digest:
bebe106babb8ba9bb80624fc3364446c78c561efb726950e21cfd758ea0c7ab3 - Sigstore transparency entry: 1429138067
- Sigstore integration time:
-
Permalink:
TimofeySukh/nuclear-random@1b2819383bb1220e188ce1e12ab8eeb080929fe1 -
Branch / Tag:
refs/tags/v0.2.2 - Owner: https://github.com/TimofeySukh
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@1b2819383bb1220e188ce1e12ab8eeb080929fe1 -
Trigger Event:
push
-
Statement type: