🎲 Generate random numbers with spacing constraints — no collisions, no clutter.
distrand lets you generate random numbers (integers or floats) between two bounds, ensuring that all values are at least min_dist apart.
Perfect for:
- Spaced-out sampling
- Visualization
- Simulation
- Teaching randomness with constraints
- 🧠 Smart spacing — every pair of values ≥
min_dist - 🧮 Supports
intandfloatgeneration - 🚫 Automatically raises
ValueErrorif impossible - ⚡ Fast and NumPy-powered
- 📜 Apache 2.0 licensed
From PyPI:
pip install distrandFrom source (for development):
git clone https://github.com/Eggman5800/distrand.git
cd distrand
pip install .from distrand import distrand
# Integer mode
nums = distrand(low=0, high=100, size=5, min_dist=10, dtype=int)
# Float mode
floats = distrand(low=0.0, high=5.0, size=4, min_dist=1.2, dtype=float)🧪 It guarantees that:
len(nums) == sizeabs(a - b) >= min_distfor alla, bpairs
Run the tests using pytest:
# Windows (PowerShell)
$env:PYTHONPATH = "src"
pytest
# Unix/macOS
PYTHONPATH=src pytest
Tests cover:
- Integer & float mode
- Invalid inputs (e.g. not enough space)
- Type conversions
python usage_demo.pyOutput:
🎲 Integer Mode Example:
Generated integers: [10 40 20 60 0]
🌊 Float Mode Example:
Generated floats: [0. 3.6 1.2 2.4]
🚫 Invalid Parameters Example:
Caught expected error: Cannot select 10 values from range [0, 10] with min_dist=5
Licensed under the Apache License 2.0.
Developed by Syed Talha.
Feedback, issues, and pull requests welcome!
- Publish to PyPI
- Add optional seed parameter (for reproducible results)
- Support output sorting (
sort=True) - Vectorized float optimization
If you find this useful, give the repo a ⭐ or share it.
Feel free to open issues.