Unified access to (some) hardware RNGs for machine learning & scientific computing
Project description
⚙️🎲 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.
Project details
Release history Release notifications | RSS feed
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 halea-0.0.1.tar.gz.
File metadata
- Download URL: halea-0.0.1.tar.gz
- Upload date:
- Size: 28.7 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
af06bf03051a73606e0e95abd4fb077f8aaecbfdb840eb4f58a0ef48a7d95c6c
|
|
| MD5 |
659fe8ca54d3a224ebd819ae04f53d12
|
|
| BLAKE2b-256 |
23d1d9337d4b857ccaf6c3d32e017efd42324017caf8258d765e5c0f98cb3faf
|
Provenance
The following attestation bundles were made for halea-0.0.1.tar.gz:
Publisher:
pypipublish.yml on emaballarin/halea
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
halea-0.0.1.tar.gz -
Subject digest:
af06bf03051a73606e0e95abd4fb077f8aaecbfdb840eb4f58a0ef48a7d95c6c - Sigstore transparency entry: 798573224
- Sigstore integration time:
-
Permalink:
emaballarin/halea@4bbf153773583794943764dcb7e10a18598d58eb -
Branch / Tag:
refs/heads/main - Owner: https://github.com/emaballarin
-
Access:
private
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
pypipublish.yml@4bbf153773583794943764dcb7e10a18598d58eb -
Trigger Event:
workflow_dispatch
-
Statement type:
File details
Details for the file halea-0.0.1-py3-none-any.whl.
File metadata
- Download URL: halea-0.0.1-py3-none-any.whl
- Upload date:
- Size: 24.0 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
7d3c14656a82fb83c5660ab6655ea901c537d2a80f0a603d40f8f314fa10346b
|
|
| MD5 |
59e0676df55fe5533adb575d40265e58
|
|
| BLAKE2b-256 |
18e6bbfddfcc49fe83b50c7cf030a588cd6629c6fa2f102a7bf717e6e7ceae4e
|
Provenance
The following attestation bundles were made for halea-0.0.1-py3-none-any.whl:
Publisher:
pypipublish.yml on emaballarin/halea
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
halea-0.0.1-py3-none-any.whl -
Subject digest:
7d3c14656a82fb83c5660ab6655ea901c537d2a80f0a603d40f8f314fa10346b - Sigstore transparency entry: 798573228
- Sigstore integration time:
-
Permalink:
emaballarin/halea@4bbf153773583794943764dcb7e10a18598d58eb -
Branch / Tag:
refs/heads/main - Owner: https://github.com/emaballarin
-
Access:
private
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
pypipublish.yml@4bbf153773583794943764dcb7e10a18598d58eb -
Trigger Event:
workflow_dispatch
-
Statement type: