https://github.com/fardinsabid/aleam
Aleam: True randomness for AI. Non-recursive, stateless, cryptographically secure random number generator.
https://github.com/fardinsabid/aleam
ai aleam cryptographic-random cuda cupy deep-learning distributions entropy gpu-acceleration jax machine-learning opensource probability pypi python pytorch random-number-generator statistics tensorflow true-randomness
Last synced: 3 months ago
JSON representation
Aleam: True randomness for AI. Non-recursive, stateless, cryptographically secure random number generator.
- Host: GitHub
- URL: https://github.com/fardinsabid/aleam
- Owner: fardinsabid
- License: mit
- Created: 2026-03-30T19:29:05.000Z (3 months ago)
- Default Branch: main
- Last Pushed: 2026-04-02T21:08:41.000Z (3 months ago)
- Last Synced: 2026-04-03T05:43:02.262Z (3 months ago)
- Topics: ai, aleam, cryptographic-random, cuda, cupy, deep-learning, distributions, entropy, gpu-acceleration, jax, machine-learning, opensource, probability, pypi, python, pytorch, random-number-generator, statistics, tensorflow, true-randomness
- Language: Python
- Homepage:
- Size: 1.3 MB
- Stars: 1
- Watchers: 0
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README

[](https://git.io/typing-svg)
[](https://python.org)
[](LICENSE)
[](https://pypi.org/project/aleam)
[](.)
[](.)
[](.)
[](.)
[](.)
[](.)
[](.)
[](.)
[](.)
[](.)
[](.)
[](.)
[](.)
[](https://github.com/fardinsabid/aleam/actions)
[](https://codecov.io/gh/fardinsabid/aleam)
[](https://pypi.org/project/aleam)

---
## π 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
```python
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)** | 128-bit true entropy from system |
| **Ο(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
### The Core Equation in Detail
| Step | Operation | Description |
|------|-----------|-------------|
| **1** | `Ξ(t) = os.urandom(16)` | Pull 128-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) |
---
## β‘ GPU Performance: Aleam vs Real Lava Lamps
| Metric | Aleam GPU | Cloudflare LavaRand |
|--------|-----------|---------------------|
| **Speed** | **93.4 MILLION ops/sec** | 11.47 ops/sec |
| **Time for 1B numbers** | **11.7 seconds** | 1,009 days |
| **Uniqueness** | **100%** | 13.3% |
| **Speedup** | **8,140,555x FASTER** | β |
*Tested on NVIDIA Tesla T4 (Google Colab) Β· CuPy 14.0.1 Β· Aleam 1.0.2*
> π‘ **Key Insight:** Lava lamps look cool on a wall, but for AI training, Aleam is 8 million times faster and delivers 100% unique random numbers.
---
## π CPU vs GPU Performance
| Metric | CPU | GPU | Speedup |
|--------|-----|-----|---------|
| **Speed** | 435K ops/sec | 93.4M ops/sec | **215x** |
| **Time for 1B numbers** | 38 minutes | 11.7 seconds | **195x** |
---
## π 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
```bash
pip install aleam
```
```python
import aleam as al
rng = al.Aleam()
# Basic randomness
x = rng.random() # 0.90324326
y = rng.randint(1, 100) # 86
z = rng.choice(['AI', 'ML']) # 'ML'
# AI/ML features
noise = rng.gauss(0, 0.1) # Gradient noise
batch = rng.sample(range(10000), 64) # Mini-batch sampling
```
---
## β¨ Features
### π² Core Randomness
| Method | Description |
|--------|-------------|
| `random()` | True random float in [0, 1) |
| `randint(a, b)` | True random integer |
| `choice(seq)` | Random element from sequence |
| `shuffle(lst)` | Shuffle list in-place |
| `sample(pop, k)` | Sample without replacement |
### π Distributions
| Distribution | Method |
|--------------|--------|
| Normal | `gauss(mu, sigma)` |
| Exponential | `exponential(rate)` |
| Beta | `beta(alpha, beta)` |
| Gamma | `gamma(shape, scale)` |
| Poisson | `poisson(lam)` |
| Laplace | `laplace(loc, scale)` |
| Logistic | `logistic(loc, scale)` |
| Log-Normal | `lognormal(mu, sigma)` |
| Weibull | `weibull(shape, scale)` |
| Pareto | `pareto(alpha, scale)` |
| Chi-square | `chi_square(df)` |
| Student's t | `student_t(df)` |
| F-distribution | `f_distribution(df1, df2)` |
| Dirichlet | `dirichlet(alpha)` |
### π§ AI/ML Features
| Class | Features |
|-------|----------|
| `AIRandom` | Gradient noise, latent vectors, dropout masks, augmentation params, mini-batch, exploration noise |
| `GradientNoise` | Gradient noise injection with decay |
| `LatentSampler` | Latent space sampling with interpolation |
### π’ Array Operations
| Function | Description |
|----------|-------------|
| `random_array(shape)` | NumPy-style random array |
| `randn_array(shape, mu, sigma)` | Normal array |
| `randint_array(shape, low, high)` | Integer array |
| `choice_array(a, size, p)` | Weighted sampling |
---
## π Framework Integrations
### PyTorch
```python
import aleam as al
gen = al.TorchGenerator(device='cuda')
tensor = gen.randn(100, 100) # True random on GPU
```
### TensorFlow
```python
import aleam as al
gen = al.TFGenerator()
tensor = gen.normal((100, 100)) # True random on GPU
```
### JAX
```python
import aleam as al
gen = al.JAXGenerator()
key = gen.key() # True random key
tensor = jax.random.normal(key, (100, 100))
```
### CuPy
```python
import aleam as al
gen = al.CuPyGenerator()
arr = gen.randn((10000, 10000)) # 100M numbers in 1 second!
```
### Pandas
```python
import aleam as al
gen = al.PandasGenerator()
df = gen.dataframe(1000, columns=['a', 'b', 'c'])
```
---
## β‘ CUDA Acceleration
Aleam provides GPU acceleration through multiple backends:
| Method | Speed (elements/sec) | Verified |
|--------|---------------------|----------|
| CPU (Python) | ~270,000 | β
|
| CPU (NumPy) | ~5,000,000 | β
|
| CuPy GPU | **~100,000,000** | β
**Verified** |
| PyTorch CUDA | ~100,000,000 | β
|
| TensorFlow GPU | ~80,000,000 | β
|
| JAX GPU | ~90,000,000 | β
|
```python
import aleam as al
# Automatic GPU acceleration (auto-detects best backend)
cuda_gen = al.CUDAGenerator()
# Works with all frameworks
cupy_arr = cuda_gen.cupy_random((10000, 10000)) # 100M numbers
torch_tensor = cuda_gen.torch_randn(10000, 10000, device='cuda')
tf_tensor = cuda_gen.tf_random_normal((10000, 10000))
```
### Distribution Performance (CPU)
| Distribution | Speed (ops/sec) |
|--------------|-----------------|
| `random()` | 270,000 |
| `uniform()` | 253,000 |
| `exponential()` | 248,000 |
| `laplace()` | 236,000 |
| `gauss()` | 129,000 |
| `gamma()` | 79,000 |
| `poisson()` | 46,000 |
| `beta()` | 41,000 |
---
## π¦ Installation
### Quick Install
```bash
pip install aleam
```
### With Framework Support
```bash
# PyTorch
pip install aleam[torch]
# TensorFlow
pip install aleam[tensorflow]
# JAX
pip install aleam[jax]
# CuPy (for maximum GPU speed)
pip install aleam[cupy]
# All frameworks
pip install aleam[all]
```
### From Source
```bash
git clone https://github.com/fardinsabid/aleam.git
cd aleam
pip install -e .
```
---
## π Project Structure
```
aleam/
βββ aleam/
β βββ __init__.py # Package exports
β βββ core.py # Aleam, AleamFast
β βββ ai.py # AIRandom, GradientNoise, LatentSampler
β βββ sources.py # SystemEntropy, HardwareEntropy
β βββ distributions.py # All statistical distributions
β βββ arrays.py # Array operations
β βββ utils.py # Helper functions
β βββ torch_integration.py # PyTorch support
β βββ tensorflow_integration.py # TensorFlow support
β βββ jax_integration.py # JAX support
β βββ cupy_integration.py # CuPy support
β βββ pandas_integration.py # Pandas support
β βββ polars_integration.py # Polars support
β βββ xarray_integration.py # Xarray support
β βββ pymc_integration.py # PyMC support
β βββ cuda_integration.py # CUDA acceleration
β βββ cuda_kernels.py # CUDA kernels
βββ tests/ # 70+ unit tests
βββ benchmarks/ # Performance benchmarks
βββ examples/ # Usage examples
βββ docs/ # Documentation
βββ setup.py # PyPI packaging
βββ README.md # You are here
βββ LICENSE # MIT License
```
---
## π§ Troubleshooting
### Q: Why is Aleam slower than random.random?
**A:** True randomness is ~37x slower than pseudo-random on CPU β that's expected. You're trading speed for genuine entropy. On GPU, Aleam can achieve 100M+ ops/sec, making it **faster than CPU pseudo-random!**
### Q: Can I seed Aleam for reproducible results?
**A:** No. Aleam is stateless by design. Use Python's `random` module if you need reproducibility.
### Q: Is Aleam cryptographically secure?
**A:** Yes. Each call consumes 128 bits of true entropy and passes through BLAKE2s, a cryptographic hash.
### Q: Will Aleam work on my phone?
**A:** Yes! Works on Android (Termux + Ubuntu) and iOS (iSH) with full functionality.
### Q: Does Aleam support GPU?
**A:** Yes! PyTorch, TensorFlow, JAX, and CuPy integrations all support GPU acceleration. Use `al.CUDAGenerator()` for automatic backend detection.
---
## π 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
| Component | License |
|-----------|---------|
| **Aleam Interface** | MIT |
| **Core Algorithm** | MIT |
| **BLAKE2s** | Public Domain / CC0 |
---
## π Links
| | |
|---|---|
| π¦ PyPI | [pypi.org/project/aleam](https://pypi.org/project/aleam) |
| π Issues | [GitHub Issues](https://github.com/fardinsabid/aleam/issues) |
| π Documentation | [GitHub Docs](https://github.com/fardinsabid/aleam/blob/main/docs/index.md) |
| π Research Paper | [ALEAM_RESEARCH_PAPER.md](https://github.com/fardinsabid/aleam/blob/main/docs/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.
[](https://github.com/fardinsabid/aleam)
[](https://github.com/fardinsabid)
**If you find this project useful, please β star it on GitHub!**