Skip to main content

Minimal hardware-backed randomness library for Python with ESP32 serial input and automatic file fallback.

Project description

randomrad - minimal package edition

randomrad is a small Python library that exposes a familiar random-like API while sourcing bytes from external entropy instead of a deterministic pseudo-random generator.

This folder contains the minimal package-style edition of the project. It is suitable for installation as a local package and for demonstrating the core API without the full GUI and report environment.

Features

  • import randomrad as rr
  • random-like functions such as randbytes, random, randint, choice, choices, shuffle and sample
  • ESP32 hardware backend over serial
  • automatic fallback to a file backend
  • host-side hardware buffer for faster repeated small requests
  • package-specific NotEnoughEntropy exception
  • no seed or replay mode by design

Installation

Open PowerShell inside this folder:

cd randomrad_pypi
python -m venv .venv
.\.venv\Scripts\activate
python -m pip install --upgrade pip
python -m pip install -e .

Quick start

import randomrad as rr

print(rr.randbytes(32))
print(rr.random())
print(rr.randint(1, 10))
print(rr.choice(["a", "b", "c"]))
print(rr.last_effective_backend())
print(rr.last_backend_detail())

Backend modes

The backend is selected with environment variables.

RANDOMRAD_BACKEND=auto|hw|file
RANDOMRAD_PORT=COM3
RANDOMRAD_BAUD=115200
RANDOMRAD_SERIAL_TIMEOUT=2.0
RANDOMRAD_HW_MAX_CHUNK=1024
RANDOMRAD_HW_BUFFER_FILL=2048
RANDOMRAD_GENERATED_ENTROPY_DIR=generated_entropy
RANDOMRAD_FILE_SIZE=8192

auto

The library first tries the ESP32 hardware backend. If the device is not available, if the port cannot be opened, or if the response is invalid, the file backend is used automatically.

hw

Only the ESP32 backend is allowed. This is useful when testing the real device because errors are not hidden by fallback behavior.

file

Only the file backend is used. This is useful for development and automated tests on machines without an ESP32.

ESP32 serial protocol

The host sends:

R <n>\n

The ESP32 answers:

S <mode>\n
D <n>\n
<n raw bytes>

The optional status mode describes the ESP32-internal entropy path:

  • adc
  • fallback
  • mixed

Included modules

  • randomrad.__init__: public package surface
  • randomrad.api: random-like user API
  • randomrad.entropy: backend selection and fallback logic
  • randomrad.exceptions: package-specific exceptions
  • randomrad.backends.file_backend: file fallback backend
  • randomrad.backends.hw_backend: ESP32 serial backend with buffering

Limitations

This package is an educational prototype. It is designed to demonstrate hardware-backed entropy, backend routing and statistical validation workflows. It should not be treated as certified cryptographic random number generation.

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

randomrad-1.0.0.tar.gz (12.2 kB view details)

Uploaded Source

Built Distribution

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

randomrad-1.0.0-py3-none-any.whl (12.9 kB view details)

Uploaded Python 3

File details

Details for the file randomrad-1.0.0.tar.gz.

File metadata

  • Download URL: randomrad-1.0.0.tar.gz
  • Upload date:
  • Size: 12.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.10.11

File hashes

Hashes for randomrad-1.0.0.tar.gz
Algorithm Hash digest
SHA256 727774a95002d2cae83bd75ed04db351861c0bff674835f1f3a6a4abbe1dc0b8
MD5 ae8b7440eb1f10ac8c190b5694f3a594
BLAKE2b-256 b4068696f414b7b37107cbdc74ef64d0d7e547c5ff220b4593f51d87029a08c9

See more details on using hashes here.

File details

Details for the file randomrad-1.0.0-py3-none-any.whl.

File metadata

  • Download URL: randomrad-1.0.0-py3-none-any.whl
  • Upload date:
  • Size: 12.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.10.11

File hashes

Hashes for randomrad-1.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 83124136d4dcc8715db2da40faa5794e37b2c0b5b8f16f7ef2f531f2db875af0
MD5 dd9b12b503a69ababa4be4f85c4efc3b
BLAKE2b-256 0038f00b8c1ff6393c60bcb897e509e9d832be308806604d3fb5bd55173009f0

See more details on using hashes here.

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