Skip to main content

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:

  1. The default randint() uses float-based scaling with negligible bias (~1e-15) for ranges under 2^53. Use unbiased=True for statistically perfect uniformity.

  2. No entropy health monitoring is performed. If a device fails, the library may return low-quality randomness.

  3. For cryptographic random bytes, use Python's secrets module or read from /dev/random directly.

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

halea-0.0.1.tar.gz (28.7 kB view details)

Uploaded Source

Built Distribution

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

halea-0.0.1-py3-none-any.whl (24.0 kB view details)

Uploaded Python 3

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

Hashes for halea-0.0.1.tar.gz
Algorithm Hash digest
SHA256 af06bf03051a73606e0e95abd4fb077f8aaecbfdb840eb4f58a0ef48a7d95c6c
MD5 659fe8ca54d3a224ebd819ae04f53d12
BLAKE2b-256 23d1d9337d4b857ccaf6c3d32e017efd42324017caf8258d765e5c0f98cb3faf

See more details on using hashes here.

Provenance

The following attestation bundles were made for halea-0.0.1.tar.gz:

Publisher: pypipublish.yml on emaballarin/halea

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

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

Hashes for halea-0.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 7d3c14656a82fb83c5660ab6655ea901c537d2a80f0a603d40f8f314fa10346b
MD5 59e0676df55fe5533adb575d40265e58
BLAKE2b-256 18e6bbfddfcc49fe83b50c7cf030a588cd6629c6fa2f102a7bf717e6e7ceae4e

See more details on using hashes here.

Provenance

The following attestation bundles were made for halea-0.0.1-py3-none-any.whl:

Publisher: pypipublish.yml on emaballarin/halea

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