Skip to main content

A Python library for generating unique random numbers with optional persistence and bitmap-based efficiency.

Project description

# unique_random

  • Generate unique random numbers efficiently, with optional persistence across runs using bitmap storage.
  • Designed for large-scale data pipelines, simulations, and systems where duplicate random values are not acceptable.

# 📦 Features

  • Generates unique random numbers in a given range
  • Optional persistence - remembers previously generated numbers between runs
  • Configurable behavior when numbers are exhausted (`error`, `reset`, `repeat`)
  • Efficient bitmap-based storage (ideal for large ranges, up to billions)
  • Command-line interface (`unirand`) for quick use
  • Well-tested and lightweight - no external dependencies

# 🧑‍💻Installation

### From GitHub (development branch)

pip install git+https://github.com/sairohithpasupuleti/unique\_random.git@develop

🧰 Basic Usage

from unique_random import UniqueRandom # Create a generator that remembers state ur = UniqueRandom(1, 100, persistent=True) for _ in range(5): print(ur.randint()) ur.close()
Output: 27 84 3 99 41

💻 Command-Line Interface (CLI)

After installation, you can use the unirand command directly in your terminal.

Generate numbers

unirand --generate 5 --start 1 --end 100

View current stats

unirand --stats --start 1 --end 100

Reset state

unirand --reset --start 1 --end 100

Example output:

Generating 5 unique numbers: 27 53 98 84 2

🚀 Options

Option Description Default
--generate N Number of values to generate -
--start N Start of range Required
--end N End of range Required
--persistent Store bitmap state for future runs False
--on-exhaust Behavior when all numbers are used (error, reset, repeat) error
--reset Reset bitmap state file -
--stats Show usage stats -

💡 Example: Persistent Mode

The persistent mode keeps track of already generated numbers using a binary bitmap file.

unirand --generate 10 --start 1 --end 1000000 --persistent

If you run it again later, it will continue generating unused numbers from the same range, without repetition.

State files are stored in:

~/.unique_random/state_<start>_<end>.bin


🧑‍💻Development Setup

git clone https://github.com/sairohithpasupuleti/unique\_random.git cd unique_random python3 -m venv .venv source .venv/bin/activate pip install -e . pytest -q

🔒 License

This project is licensed under the MIT License.
See the LICENSE file for full details.


👤 Author

Sai Rohith Pasupuleti
📧 sairohithpasupuleti@gmail.com
🌐 GitHub Repository

🧭 Roadmap

  • Add C-backed bitmap for improved speed (v1.1)
  • Optional multi-threaded random generation
  • Built-in benchmarking mode
  • Integration tests with 1B+ values

🤝 Contributing

Contributions are welcome!🧑‍💻
If you'd like to improve this package:

  • Fork the repository
  • Create a new branch (feature/...)
  • Submit a pull request

⭐ Support

If you find this project useful, please consider starring it on GitHub.
Your support motivates continued development.

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

unique_random-1.0.0.tar.gz (7.2 kB view details)

Uploaded Source

Built Distribution

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

unique_random-1.0.0-py3-none-any.whl (8.1 kB view details)

Uploaded Python 3

File details

Details for the file unique_random-1.0.0.tar.gz.

File metadata

  • Download URL: unique_random-1.0.0.tar.gz
  • Upload date:
  • Size: 7.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.14.0

File hashes

Hashes for unique_random-1.0.0.tar.gz
Algorithm Hash digest
SHA256 82773455419b6e483dbd550b77ea5997cf53315c7c493d6f2a6c78872d1dd964
MD5 099e9dad4c194ab0505ed68f3a3f7af4
BLAKE2b-256 83470c6610ac3f5ba2e3391a6a644c3517c152bcf5c9ae35c87c10ea302d9680

See more details on using hashes here.

File details

Details for the file unique_random-1.0.0-py3-none-any.whl.

File metadata

  • Download URL: unique_random-1.0.0-py3-none-any.whl
  • Upload date:
  • Size: 8.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.14.0

File hashes

Hashes for unique_random-1.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 d59e825ea01252559d1884ce47f5c0bca1ec4a518573673b1e8d58ee4912d1c9
MD5 b9a35feace0aab156bd2e311d7f776c4
BLAKE2b-256 3ad0c0a70985fd4d6370e0d9019fc06907f8b6b5ce613ef2ae6617ee390b1757

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