⚙️🎲 HAlea
Unified access to (some) hardware RNGs for machine learning & scientific computing
Supported Devices
| Device | Interface | Backend |
|---|---|---|
| TrueRNGpro | USB Serial | truerng |
| ChaosKey | USB Bulk | chaoskey |
Features
- Three APIs: NumPy (
HaleaNumpy), PyTorch (HaleaTorch), JAX (HaleaJax) - Distributions: uniform, normal (Box-Muller), integers, bits, bytes
- Sampling:
choice()with/without replacement,shuffle(),permutation() - Auto-detection: Finds connected devices automatically
- Buffered I/O: Efficient bulk reads with configurable buffer size
- Unbiased mode: Optional rejection sampling for perfect uniformity
Quick Start
from halea import HaleaNumpy
with HaleaNumpy() as rng:
# Uniform [0, 1)
x = rng.rand(1000)
# Normal N(0, 1)
y = rng.randn(100, 100)
# Integers [0, 100)
z = rng.randint(100, size=50)
# Shuffle in-place
rng.shuffle(my_list)
PyTorch / JAX:
from halea import HaleaTorch, HaleaJax
with HaleaTorch(device="cuda") as rng:
tensor = rng.randn(256, 256, dtype=torch.float32)
with HaleaJax() as rng:
array = rng.normal(shape=(256, 256))
Installation
pip install halea
Requirements: numpy, pyserial, pyusb
Optional: torch, jax (for respective APIs)
Linux udev rules (for non-root access):
# TrueRNG
echo 'SUBSYSTEM=="tty", ATTRS{idVendor}=="04d8", ATTRS{idProduct}=="f5fe", MODE="0666"' | sudo tee /etc/udev/rules.d/99-truerng.rules
# ChaosKey
echo 'SUBSYSTEM=="usb", ATTR{idVendor}=="1d50", ATTR{idProduct}=="60c6", MODE="0666"' | sudo tee /etc/udev/rules.d/99-chaoskey.rules
sudo udevadm control --reload-rules
Scope & Limitations
- For ML/scientific use — not cryptographic applications
- Single-threaded — create separate instances for multi-threaded use
- No entropy monitoring — assumes device is functioning correctly
- Linux-focused — other platforms may work but are untested
Security Notice
This library provides access to hardware random number generators for machine learning and scientific computing applications. It is NOT designed for cryptographic use.
For cryptographic applications:
-
The default
randint()uses float-based scaling with negligible bias (~1e-15) for ranges under 2^53. Useunbiased=Truefor statistically perfect uniformity. -
No entropy health monitoring is performed. If a device fails, the library may return low-quality randomness.
-
For cryptographic random bytes, use Python's
secretsmodule or read from/dev/randomdirectly.
Metadata
Release files for halea 0.0.1
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| halea-0.0.1.tar.gz | 28.7 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| halea-0.0.1-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 52.7 kB
Release files / halea-0.0.1.tar.gz
| Download URL | halea-0.0.1.tar.gz |
|---|---|
| Size | 28.7 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
af06bf03051a73606e0e95abd4fb077f8aaecbfdb840eb4f58a0ef48a7d95c6c
|
|
BLAKE2b-256 checksum How to use checksums |
23d1d9337d4b857ccaf6c3d32e017efd42324017caf8258d765e5c0f98cb3faf
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/6.1.0 CPython/3.13.7
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Jan 6, 2026.
Transparency logRelease files / halea-0.0.1-py3-none-any.whl
| Download URL | halea-0.0.1-py3-none-any.whl |
|---|---|
| Size | 24.0 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
7d3c14656a82fb83c5660ab6655ea901c537d2a80f0a603d40f8f314fa10346b
|
|
BLAKE2b-256 checksum How to use checksums |
18e6bbfddfcc49fe83b50c7cf030a588cd6629c6fa2f102a7bf717e6e7ceae4e
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/6.1.0 CPython/3.13.7
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Jan 6, 2026.
Transparency log