Generate spaced random numbers with minimum distance constraints.
Project description
distrand
🎲 Generate random numbers with spacing constraints — no collisions, no clutter.
📦 What is this?
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
🔧 Features
- 🧠 Smart spacing — every pair of values ≥
min_dist - 🧮 Supports
intandfloatgeneration - 🚫 Automatically raises
ValueErrorif impossible - ⚡ Fast and NumPy-powered
- 📜 Apache 2.0 licensed
🚀 Installation
Python 3.7+ and NumPy are required.
git clone https://github.com/Eggman5800/distrand.git
cd distrand
pip install .
📚 Usage
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
🧪 Testing
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
🧑💻 Example Run
python usage_demo.py
Output:
🎲 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
🛡️ License
Licensed under the Apache License 2.0.
💡 Credits
Developed by Syed Talha.
Feedback, issues, and pull requests welcome!
🌠 Roadmap
- Publish to PyPI
- Add optional seed parameter
- Support output sorting (
sort=True) - Vectorized float optimization
🙌 Support
If you find this useful, give the repo a ⭐ or share it.
Feel free to open issues.
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 distrand-0.1.0.tar.gz.
File metadata
- Download URL: distrand-0.1.0.tar.gz
- Upload date:
- Size: 7.7 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.12.6
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
45dc52dbfa875e9d2cfbaaae862cc5585bf5db8760f6e145160d969d53e290f5
|
|
| MD5 |
f97c52fd71831775f0c3dc3befa657be
|
|
| BLAKE2b-256 |
493f1af4846a1d830585b5f8a80a2453450510fb6236e5da4d80050653db4e9e
|
File details
Details for the file distrand-0.1.0-py3-none-any.whl.
File metadata
- Download URL: distrand-0.1.0-py3-none-any.whl
- Upload date:
- Size: 8.1 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.12.6
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
780952126d43ae2a7109afde93c284302eea80d25467f0090e1ff7dfc1ec0c8a
|
|
| MD5 |
c8fa2f370e404f208446b33922f3c056
|
|
| BLAKE2b-256 |
f06f203f80258f7fafc67217874eae5e079cd5e5002d9e2cfd25c8656e820bd9
|