Skip to main content

True randomness for AI and machine learning. Non-recursive, stateless, cryptographically secure random number generator.

Project description

Typing SVG


Python License PyPI Platform


Stats Entropy Hash C++


PyTorch TensorFlow JAX CuPy


NumPy Pandas Polars Dask


Tests Coverage Downloads



๐Ÿ“Œ The Problem

Pseudo-random number generators (PRNGs) like Mersenne Twister and Python's random are recursive:

xโ‚™โ‚Šโ‚ = (aยทxโ‚™ + c) mod m

This creates:

  • ๐Ÿ” Hidden correlations โ€” each number depends on the one before
  • ๐Ÿ“… Periodicity โ€” sequences eventually repeat
  • ๐Ÿงฑ Exploration boundaries โ€” AI can't truly explore
  • ๐ŸŽญ False reproducibility โ€” same seed = same path

AI deserves better.


๐ŸŽฏ The Solution: Aleam

import aleam as al

rng = al.Aleam()
x = rng.random()  # True randomness. No recursion. No state.

Aleam implements the proven equation:

ฮจ(t) = BLAKE2s( (ฮฆ ร— ฮž(t)) โŠ• ฯ„(t) )
Symbol Meaning
ฮฆ Golden ratio prime (0x9E3779B97F4A7C15)
ฮž(t) 64-bit true entropy from system CSPRNG
ฯ„(t) Nanosecond timestamp
โŠ• XOR mixing
BLAKE2s Cryptographic hash

Properties:

๐Ÿ”„ Non-recursive ๐ŸŽฒ Stateless ๐Ÿ”’ Cryptographically Secure ๐Ÿง  AI-Optimized
Each call independent No seeds, no state Powered by BLAKE2s Gradient noise, latent sampling

๐Ÿ”ฌ How It Works

Aleam Core Algorithm

The Core Equation in Detail

Step Operation Description
1 ฮž(t) = get_entropy_64() Pull 64-bit true entropy from system
2 ฮฉ = ฮฆ ร— ฮž(t) Golden ratio mixing (bijective, maximally equidistributed)
3 ฯ„ = time.time_ns() Nanosecond timestamp for uniqueness
4 ฮฃ = ฮฉ โŠ• ฯ„ XOR mixing over 64 bits
5 ฯˆ = BLAKE2s(ฮฃ) Cryptographic hash to 64-bit output
6 r = ฯˆ / 2โถโด Map to floating point [0, 1)

โšก Performance: CPU vs GPU

Aleam CPU vs GPU

Metric CPU (Python) CPU (C++ Core) GPU (CuPy)
Speed Coming soon Coming soon Coming soon
vs Python Coming soon Coming soon Coming soon
Time for 1B numbers Coming soon Coming soon Coming soon

Benchmarks pending - will be updated after Colab testing

๐Ÿ’ก Key Insight: The C++ migration delivers significant CPU speedup over pure Python, while GPU acceleration provides massive parallel performance.


๐Ÿ“Š Statistical Validation

After 2.55 million samples, Aleam passed all 10 rigorous tests:

Test Result Status
Mean 0.499578 โœ“
Variance 0.083154 โœ“
Chi-Square (Uniformity) 21.40 (critical 30.14) โœ“ PASS
Max Autocorrelation 0.0094 โœ“ EXCELLENT
ฯ€ Estimation Error 0.0105% โœ“ EXCELLENT
Shannon Entropy 0.9999 โœ“ NEAR-PERFECT

"True randomness is not a bug โ€” it's a feature."


๐Ÿš€ Quick Start

Install from PyPI (recommended)

pip install aleam

Install from source

git clone https://github.com/fardinsabid/aleam.git
cd aleam
pip install .

Basic Usage

import aleam as al

# Create a true random generator
rng = al.Aleam()

# Core randomness
x = rng.random()                    # 0.90324326
u64 = rng.random_uint64()           # 12345678901234567890
y = rng.randint(1, 100)             # 86
z = rng.choice(['AI', 'ML', 'Aleam'])  # 'ML'
u = rng.uniform(5.0, 10.0)          # 7.234
n = rng.gauss(0.0, 1.0)            # -0.432

# Sampling (requires list, not range)
population = list(range(10000))
batch = rng.sample(population, 64)  # Random 64 unique indices

# Shuffle list in-place
items = [1, 2, 3, 4, 5]
rng.shuffle(items)                  # [3, 1, 5, 2, 4]

# Random bytes for cryptography
key = rng.random_bytes(32)          # 32 cryptographically secure bytes

โœจ Features

๐ŸŽฒ Core Randomness

Method Description Example
random() True random float in [0, 1) rng.random()
random_uint64() True random 64-bit integer rng.random_uint64()
randint(a, b) Random integer in [a, b] rng.randint(1, 100)
choice(seq) Random element from sequence rng.choice(['a', 'b', 'c'])
shuffle(lst) Shuffle list in-place rng.shuffle(my_list)
sample(pop, k) Sample k unique elements rng.sample(list(range(100)), 10)
random_bytes(n) Generate n random bytes rng.random_bytes(32)

๐Ÿ“ˆ Statistical Distributions

Distribution Method Example
Uniform uniform(low, high) rng.uniform(5, 10)
Normal (Gaussian) gauss(mu, sigma) rng.gauss(0, 1)
Exponential exponential(rate) rng.exponential(1.0)
Beta beta(alpha, beta) rng.beta(2, 5)
Gamma gamma(shape, scale) rng.gamma(2, 1)
Poisson poisson(lam) rng.poisson(3.5)
Laplace laplace(loc, scale) rng.laplace(0, 1)
Logistic logistic(loc, scale) rng.logistic(0, 1)
Log-Normal lognormal(mu, sigma) rng.lognormal(0, 1)
Weibull weibull(shape, scale) rng.weibull(1.5, 1)
Pareto pareto(alpha, scale) rng.pareto(2, 1)
Chi-square chi_square(df) rng.chi_square(5)
Student's t student_t(df) rng.student_t(3)
F-distribution f_distribution(df1, df2) rng.f_distribution(5, 10)
Dirichlet dirichlet(alpha) rng.dirichlet([1, 2, 3])

๐Ÿง  AI/ML Features

Class Methods Use Case
AIRandom gradient_noise(), latent_vector(), dropout_mask(), augmentation_params(), mini_batch(), exploration_noise() Training, augmentation, RL exploration
GradientNoise add_noise(), reset(), current_scale() Gradient noise injection with decay
LatentSampler sample(), sample_one(), interpolate() Latent space sampling for VAEs/GANs

๐Ÿ”ข Array Operations

Function Description Example
random_array(shape) Uniform random array al.random_array((100, 100))
randn_array(shape, mu, sigma) Normal random array al.randn_array(1000, 0, 1)
randint_array(shape, low, high) Integer random array al.randint_array((50,), 0, 10)
choice_array(a, size, replace, p) Weighted sampling al.choice_array(fruits, size=100, p=weights)

๐Ÿ”Œ Framework Integrations

PyTorch

import torch
import aleam as al

gen = al.TorchGenerator(device='cuda' if torch.cuda.is_available() else 'cpu')
tensor = gen.randn(100, 100)      # True random tensor on GPU
tensor = gen.rand(100, 100)       # Uniform [0, 1) tensor
tensor = gen.randint(0, 10, (100, 100))  # Integer tensor

TensorFlow

import tensorflow as tf
import aleam as al

gen = al.TFGenerator()
tensor = gen.normal((100, 100), mean=0, stddev=1)
tensor = gen.uniform((100, 100), minval=0, maxval=1)
tensor = gen.randint((100, 100), minval=0, maxval=10)

JAX

import jax
import aleam as al

gen = al.JAXGenerator()
key = gen.key()                   # True random key
tensor = jax.random.normal(key, (100, 100))

CuPy (Fastest GPU)

import cupy as cp
import aleam as al

gen = al.CuPyGenerator()
arr = gen.randn((10000, 10000))   # True random on GPU
arr = gen.random((10000, 10000))  # Uniform on GPU
arr = gen.randint((10000, 10000), 0, 10)

Pandas

import pandas as pd
import aleam as al

gen = al.PandasGenerator()
series = gen.series(1000, distribution="normal", params="mu=0,sigma=1")
df = gen.dataframe(1000, columns=['a', 'b', 'c'])
shuffled = gen.shuffle(df)

NumPy

import aleam as al
import numpy as np

# Direct array generation
arr = al.random_array((100, 100))      # Returns list, convert to numpy if needed
np_arr = np.array(arr)

# Or use module-level functions
arr = al.random_array((1000,))          # 1D array
matrix = al.random_array((10, 10))      # 2D matrix
norm_arr = al.randn_array(1000, 0, 1)   # Normal distribution
int_arr = al.randint_array((50,), 0, 10) # Integers

โšก CUDA Acceleration

Aleam provides GPU acceleration through multiple backends:

Method Speed
CPU (Python) Coming soon
CPU (C++ Core) Coming soon
CuPy GPU Coming soon
PyTorch CUDA Coming soon
TensorFlow GPU Coming soon
JAX GPU Coming soon
import aleam as al

# Automatic GPU acceleration (auto-detects best backend)
cuda_gen = al.CUDAGenerator()

# Generate true random numbers on GPU
cupy_arr = cuda_gen.cupy_random((10000, 10000))

# Or use with specific frameworks
torch_tensor = cuda_gen.torch_randn(10000, 10000, device='cuda')
tf_tensor = cuda_gen.tf_random_normal((10000, 10000))

๐Ÿ“ฆ Installation Details

From PyPI (recommended for users)

pip install aleam

With Framework Support

# PyTorch
pip install aleam[torch]

# TensorFlow
pip install aleam[tensorflow]

# JAX
pip install aleam[jax]

# CuPy (for maximum GPU speed)
pip install aleam[cupy]

# Data science
pip install aleam[pandas]

# All frameworks
pip install aleam[all]

From Source (for development)

git clone https://github.com/fardinsabid/aleam.git
cd aleam
pip install .

Development Installation

pip install -e .[dev]

๐Ÿ“ Project Structure

aleam/
โ”‚
โ”œโ”€โ”€ .github/
โ”‚   โ””โ”€โ”€ workflows/
โ”‚       โ”œโ”€โ”€ tests.yml
โ”‚       โ”œโ”€โ”€ publish.yml
โ”‚       โ”œโ”€โ”€ security.yml
โ”‚       โ””โ”€โ”€ docs.yml
โ”‚
โ”œโ”€โ”€ aleam/
โ”‚   โ”‚
โ”‚   โ”œโ”€โ”€ __init__.py
โ”‚   โ””โ”€โ”€ py.typed
โ”‚
โ”œโ”€โ”€ src/
โ”‚   โ”‚
โ”‚   โ””โ”€โ”€ aleam/
โ”‚       โ”‚
โ”‚       โ”œโ”€โ”€ bindings/
โ”‚       โ”‚   โ”œโ”€โ”€ module.cpp
โ”‚       โ”‚   โ””โ”€โ”€ exports.h
โ”‚       โ”‚
โ”‚       โ”œโ”€โ”€ core/
โ”‚       โ”‚   โ”œโ”€โ”€ aleam_core.h
โ”‚       โ”‚   โ”œโ”€โ”€ aleam_core.cpp
โ”‚       โ”‚   โ”œโ”€โ”€ constants.h
โ”‚       โ”‚   โ””โ”€โ”€ utils.h
โ”‚       โ”‚
โ”‚       โ”œโ”€โ”€ entropy/
โ”‚       โ”‚   โ”œโ”€โ”€ entropy.h
โ”‚       โ”‚   โ”œโ”€โ”€ entropy_linux.h
โ”‚       โ”‚   โ”œโ”€โ”€ entropy_windows.h
โ”‚       โ”‚   โ””โ”€โ”€ entropy_darwin.h
โ”‚       โ”‚
โ”‚       โ”œโ”€โ”€ hash/
โ”‚       โ”‚   โ”œโ”€โ”€ blake2s.h
โ”‚       โ”‚   โ””โ”€โ”€ blake2s_config.h
โ”‚       โ”‚
โ”‚       โ”œโ”€โ”€ distributions/
โ”‚       โ”‚   โ”œโ”€โ”€ distributions.h
โ”‚       โ”‚   โ”œโ”€โ”€ distributions.cpp
โ”‚       โ”‚   โ”œโ”€โ”€ normal.h
โ”‚       โ”‚   โ”œโ”€โ”€ exponential.h
โ”‚       โ”‚   โ”œโ”€โ”€ beta.h
โ”‚       โ”‚   โ”œโ”€โ”€ gamma.h
โ”‚       โ”‚   โ”œโ”€โ”€ poisson.h
โ”‚       โ”‚   โ”œโ”€โ”€ laplace.h
โ”‚       โ”‚   โ”œโ”€โ”€ logistic.h
โ”‚       โ”‚   โ”œโ”€โ”€ lognormal.h
โ”‚       โ”‚   โ”œโ”€โ”€ weibull.h
โ”‚       โ”‚   โ”œโ”€โ”€ pareto.h
โ”‚       โ”‚   โ”œโ”€โ”€ chi_square.h
โ”‚       โ”‚   โ”œโ”€โ”€ student_t.h
โ”‚       โ”‚   โ”œโ”€โ”€ f_distribution.h
โ”‚       โ”‚   โ””โ”€โ”€ dirichlet.h
โ”‚       โ”‚
โ”‚       โ”œโ”€โ”€ arrays/
โ”‚       โ”‚   โ”œโ”€โ”€ arrays.h
โ”‚       โ”‚   โ”œโ”€โ”€ arrays.cpp
โ”‚       โ”‚   โ””โ”€โ”€ array_utils.h
โ”‚       โ”‚
โ”‚       โ”œโ”€โ”€ ai/
โ”‚       โ”‚   โ”œโ”€โ”€ ai.h
โ”‚       โ”‚   โ”œโ”€โ”€ ai.cpp
โ”‚       โ”‚   โ”œโ”€โ”€ gradient_noise.h
โ”‚       โ”‚   โ”œโ”€โ”€ latent_sampler.h
โ”‚       โ”‚   โ””โ”€โ”€ augmentation.h
โ”‚       โ”‚
โ”‚       โ”œโ”€โ”€ integrations/
โ”‚       โ”‚   โ”œโ”€โ”€ integrations.h
โ”‚       โ”‚   โ”œโ”€โ”€ integrations.cpp
โ”‚       โ”‚   โ”œโ”€โ”€ torch_integration.h
โ”‚       โ”‚   โ”œโ”€โ”€ torch_integration.cpp
โ”‚       โ”‚   โ”œโ”€โ”€ tensorflow_integration.h
โ”‚       โ”‚   โ”œโ”€โ”€ tensorflow_integration.cpp
โ”‚       โ”‚   โ”œโ”€โ”€ jax_integration.h
โ”‚       โ”‚   โ”œโ”€โ”€ jax_integration.cpp
โ”‚       โ”‚   โ”œโ”€โ”€ cupy_integration.h
โ”‚       โ”‚   โ”œโ”€โ”€ cupy_integration.cpp
โ”‚       โ”‚   โ”œโ”€โ”€ pandas_integration.h
โ”‚       โ”‚   โ”œโ”€โ”€ pandas_integration.cpp
โ”‚       โ”‚   โ”œโ”€โ”€ polars_integration.h
โ”‚       โ”‚   โ”œโ”€โ”€ polars_integration.cpp
โ”‚       โ”‚   โ”œโ”€โ”€ xarray_integration.h
โ”‚       โ”‚   โ”œโ”€โ”€ xarray_integration.cpp
โ”‚       โ”‚   โ”œโ”€โ”€ pymc_integration.h
โ”‚       โ”‚   โ”œโ”€โ”€ pymc_integration.cpp
โ”‚       โ”‚   โ”œโ”€โ”€ dask_integration.h
โ”‚       โ”‚   โ””โ”€โ”€ dask_integration.cpp
โ”‚       โ”‚
โ”‚       โ””โ”€โ”€ cuda/
โ”‚           โ”œโ”€โ”€ cuda_kernels.h
โ”‚           โ”œโ”€โ”€ cuda_kernels.cu
โ”‚           โ”œโ”€โ”€ cuda_uniform.cu
โ”‚           โ”œโ”€โ”€ cuda_normal.cu
โ”‚           โ””โ”€โ”€ cuda_utils.h
โ”‚
โ”œโ”€โ”€ include/
โ”‚   โ””โ”€โ”€ aleam/
โ”‚       โ””โ”€โ”€ aleam.h
โ”‚
โ”œโ”€โ”€ tests/
โ”‚   โ”œโ”€โ”€ test_core.py
โ”‚   โ”œโ”€โ”€ test_ai.py
โ”‚   โ””โ”€โ”€ test_statistical.py
โ”‚
โ”œโ”€โ”€ benchmarks/
โ”‚   โ””โ”€โ”€ benchmark_core.py
โ”‚
โ”œโ”€โ”€ assets/
โ”‚   โ””โ”€โ”€ images/
โ”‚       โ”œโ”€โ”€ benchmarks/
โ”‚       โ”‚   โ”œโ”€โ”€ aleam_gpu_vs_lavarand_hd.png
โ”‚       โ”‚   โ””โ”€โ”€ cpu_vs_gpu.png
โ”‚       โ””โ”€โ”€ diagrams/
โ”‚            โ””โ”€โ”€ algorithm.png
โ”‚
โ”‚           
โ”œโ”€โ”€ examples/
โ”‚   โ”œโ”€โ”€ basic_usage.py
โ”‚   โ”œโ”€โ”€ ai_ml_features.py
โ”‚   โ”œโ”€โ”€ array_operations.py
โ”‚   โ”œโ”€โ”€ distributions.py
โ”‚   โ”œโ”€โ”€ monte_carlo_pi.py
โ”‚   โ”œโ”€โ”€ reinforcement_learning.py
โ”‚   โ”œโ”€โ”€ cuda_integration.py
โ”‚   โ”œโ”€โ”€ pytorch_integration.py
โ”‚   โ””โ”€โ”€ tensorflow_integration.py
โ”‚
โ”œโ”€โ”€ docs/
โ”‚   โ”œโ”€โ”€ ALEAM_RESEARCH_PAPER.md
โ”‚   โ””โ”€โ”€ index.md
โ”‚
โ”œโ”€โ”€ setup.py
โ”œโ”€โ”€ pyproject.toml
โ”œโ”€โ”€ MANIFEST.in
โ”œโ”€โ”€ requirements.txt
โ”œโ”€โ”€ requirements-dev.txt
โ”œโ”€โ”€ LICENSE
โ”œโ”€โ”€ README.md
โ”œโ”€โ”€ CONTRIBUTING.md
โ””โ”€โ”€ .gitignore

๐Ÿ”ง Troubleshooting

Q: Why is Aleam slower than random.random on CPU?

A: True randomness is slower than pseudo-random with the C++ core โ€” that's expected. You're trading speed for genuine entropy. On GPU, Aleam achieves massive parallel performance.

Q: Can I seed Aleam for reproducible results?

A: No. Aleam is stateless by design. Call al.seed_free() to see the explanation. Use Python's random module if you need reproducibility.

Q: Is Aleam cryptographically secure?

A: Yes. Each call consumes 64 bits of true entropy and passes through BLAKE2s, a cryptographic hash.

Q: Does Aleam support GPU?

A: Yes! PyTorch, TensorFlow, JAX, and CuPy integrations all support GPU acceleration. Use al.CUDAGenerator() for automatic backend detection.

Q: Why does sample() require a list?

A: The C++ bindings accept Python lists directly. Use list(range(10000)) instead of range(10000).

Q: Will Aleam work on my platform?

A: Yes! Linux (getrandom), Windows (BCrypt), and macOS (arc4random) are all supported.


๐Ÿ”’ Responsible Use

  • โœ… Use for AI research, exploration, and creative projects
  • โœ… Use for scientific simulations requiring true randomness
  • โœ… Use for cryptographic applications
  • โŒ Do not use for security-critical systems without additional entropy sources
  • โŒ Do not use to generate deceptive or harmful content

๐Ÿ“„ License

MIT License โ€” see LICENSE for details.

Component License
Aleam Interface MIT
Core Algorithm MIT
BLAKE2s Public Domain / CC0

๐ŸŒ Links

๐Ÿ“ฆ PyPI pypi.org/project/aleam
๐Ÿ› Issues GitHub Issues
๐Ÿ“– Documentation GitHub Docs
๐Ÿ“„ Research Paper ALEAM_RESEARCH_PAPER.md

๐Ÿ™ Acknowledgments

  • BLAKE2 team for the cryptographic hash function
  • Open-source community for entropy source implementations
  • Python community for the amazing ecosystem

Made with โค๏ธ by Fardin Sabid
๐Ÿ‡ง๐Ÿ‡ฉ From Bangladesh, for the World ๐ŸŒ


True randomness. No recursion. No state. Just entropy.

After 2 days of discovery, testing, and refinement โ€” the equation is proven.


GitHub stars Follow

If you find this project useful, please โญ star it on GitHub!

```

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distributions

No source distribution files available for this release.See tutorial on generating distribution archives.

Built Distributions

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

aleam-1.0.3-py3-none-any.whl (3.1 MB view details)

Uploaded Python 3

aleam-1.0.3-cp312-cp312-manylinux2014_x86_64.whl (3.1 MB view details)

Uploaded CPython 3.12

aleam-1.0.3-cp312-cp312-manylinux2014_aarch64.whl (3.0 MB view details)

Uploaded CPython 3.12

aleam-1.0.3-cp312-cp312-macosx_10_13_universal2.whl (423.7 kB view details)

Uploaded CPython 3.12macOS 10.13+ universal2 (ARM64, x86-64)

File details

Details for the file aleam-1.0.3-py3-none-any.whl.

File metadata

  • Download URL: aleam-1.0.3-py3-none-any.whl
  • Upload date:
  • Size: 3.1 MB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.7

File hashes

Hashes for aleam-1.0.3-py3-none-any.whl
Algorithm Hash digest
SHA256 f5b2814355d662b2fb4199141b528b4a92d35458ca35f10008be64b1ae016258
MD5 7ede9d25779495d35cc8ab7949dd15c7
BLAKE2b-256 3d5b028e274c26bf8ead380dbeff8c5352c512788d9eb775300a0de8c3cc6761

See more details on using hashes here.

File details

Details for the file aleam-1.0.3-cp312-cp312-manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for aleam-1.0.3-cp312-cp312-manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 626feeae03dad83b76e406d9f7993fc70bbaa7fde74fd1c7c47af77c8bc93075
MD5 b48e6348d77b44a4e1a7efae736b079b
BLAKE2b-256 baf3f3d562859b4d2db097726d9ce370789bb15d0c405527651e026851b68a3f

See more details on using hashes here.

File details

Details for the file aleam-1.0.3-cp312-cp312-manylinux2014_aarch64.whl.

File metadata

File hashes

Hashes for aleam-1.0.3-cp312-cp312-manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 b0804decb968effb0c545ce8e42534da68a4d246b965ba647b3b455e5db67957
MD5 6b611f6b17a35f45fa379bb8212bc866
BLAKE2b-256 1eead705212f32552de2c84e58895b6a36c255617f1702a98f15931856ebc604

See more details on using hashes here.

File details

Details for the file aleam-1.0.3-cp312-cp312-macosx_10_13_universal2.whl.

File metadata

File hashes

Hashes for aleam-1.0.3-cp312-cp312-macosx_10_13_universal2.whl
Algorithm Hash digest
SHA256 930c4e8907189f159f68684d85fbd151e9c1a2175f6387bbcd38b42cf48a98de
MD5 3f8a8ced9d36243335cda0dc83d5515f
BLAKE2b-256 ac4869856c826f1e6f2d0f5f6292c625c5660ded63a6d2f52fe723efd8d17378

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