Skip to main content

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 int and float generation
  • 🚫 Automatically raises ValueError if 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) == size
  • abs(a - b) >= min_dist for all a, b pairs

🧪 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


Download files

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

Source Distribution

distrand-0.1.1.tar.gz (7.7 kB view details)

Uploaded Source

Built Distribution

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

distrand-0.1.1-py3-none-any.whl (8.1 kB view details)

Uploaded Python 3

File details

Details for the file distrand-0.1.1.tar.gz.

File metadata

  • Download URL: distrand-0.1.1.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

Hashes for distrand-0.1.1.tar.gz
Algorithm Hash digest
SHA256 9732b49d424268c926dd801e6c0212c037bd9b13d42c4f70db465fd02f1b5ff1
MD5 89460b41b64bd6c14b347e55723330c2
BLAKE2b-256 b715fd76a6c0178800fb169badac2fb1360e92c8c7b287434767c326ae7d2cea

See more details on using hashes here.

File details

Details for the file distrand-0.1.1-py3-none-any.whl.

File metadata

  • Download URL: distrand-0.1.1-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

Hashes for distrand-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 27c73d2fbdbbabd9e5fad994a2fed8ddaa31e34630de1b3eac1c6d7a11c545ad
MD5 fdad1ce14d0a2b9116be7acee4cf5455
BLAKE2b-256 3f773003b519a07a5a2bdf08f6083fcc8dd1d231fb2e87a8f322b9688c2ed8b0

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