Skip to main content

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 (
    nuclear_choice,
    nuclear_randint,
    nuclear_random,
    nuclear_random_bytes,
    service_status,
)

print(nuclear_random(100))      # 0..100 inclusive
print(nuclear_random(10_000))   # 0..10000 inclusive
print(nuclear_randint(10, 20))  # 10..20 inclusive
print(nuclear_random_bytes(16).hex())
print(nuclear_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 (
    nuclear_choice,
    nuclear_randint,
    nuclear_random,
    nuclear_random_bytes,
    service_status,
)
  • nuclear_random(max_value) returns an integer in 0..max_value.
  • nuclear_randint(min_value, max_value) returns an integer in min_value..max_value.
  • nuclear_choice(items) returns one item from a non-empty sequence by drawing a QRNG-backed index.
  • nuclear_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.

The shorter names randint, choice, and random_bytes remain as backward-compatible aliases.

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

nuclear_random-0.2.3.tar.gz (29.5 kB view details)

Uploaded Source

Built Distribution

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

nuclear_random-0.2.3-py3-none-any.whl (6.7 kB view details)

Uploaded Python 3

File details

Details for the file nuclear_random-0.2.3.tar.gz.

File metadata

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

File hashes

Hashes for nuclear_random-0.2.3.tar.gz
Algorithm Hash digest
SHA256 8bd174041ed49c673b9da372f500c47d96757da49044afc1933ddd2368afd685
MD5 0a57301db14c9ca5470c762d66b57d29
BLAKE2b-256 083a412af62cafe4876300cfb59da5dc23d2749e5f1cb087e8cb7a7c0d647653

See more details on using hashes here.

Provenance

The following attestation bundles were made for nuclear_random-0.2.3.tar.gz:

Publisher: publish.yml on TimofeySukh/nuclear-random

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

File details

Details for the file nuclear_random-0.2.3-py3-none-any.whl.

File metadata

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

File hashes

Hashes for nuclear_random-0.2.3-py3-none-any.whl
Algorithm Hash digest
SHA256 6b901aa5d196372b848dcd9808d466cf3d35920f4dadc192ddb198c6e0854d37
MD5 6eae520da3c5de6cc7f0b83df449e1bf
BLAKE2b-256 dec7bfcbf318fe22a69925d89dde949feb6c515b3435b2504e96a71ff9ca2401

See more details on using hashes here.

Provenance

The following attestation bundles were made for nuclear_random-0.2.3-py3-none-any.whl:

Publisher: publish.yml on TimofeySukh/nuclear-random

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