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.

PyPI version License

📦 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

From PyPI:

pip install distrand

From source (for development):

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 (for reproducible results)
  • 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.2.tar.gz (8.0 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.2-py3-none-any.whl (8.0 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: distrand-0.1.2.tar.gz
  • Upload date:
  • Size: 8.0 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.2.tar.gz
Algorithm Hash digest
SHA256 36a424b6f97a9bdca3ff73bd8e96a7d2cf6b72a9f486d38a41fd887a34a244dd
MD5 bc1f16528f9eb59f49df21b956aec6a2
BLAKE2b-256 af142d1fd748302768a3ac224d97565737d86fade9fc0e9dd482f2784140a1b5

See more details on using hashes here.

File details

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

File metadata

  • Download URL: distrand-0.1.2-py3-none-any.whl
  • Upload date:
  • Size: 8.0 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.2-py3-none-any.whl
Algorithm Hash digest
SHA256 5c0848eed76613390debde55f57e400e6cd54f7f7655706e554ae027bf06ea89
MD5 631e80ea99a118fe1dfbdfaf5e928fae
BLAKE2b-256 50d38cc8544cfad1a5113e1ae59e575f9b0523eca69440e5131fcbe6980c35cd

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