A weighted random selection tool for probabilistic item selection
Project description
Weighted Randomizer
A Python utility for weighted random selection of items. Useful for probabilistic distributions, lotteries, and random sampling with custom probabilities.
Installation
pip install -e .
Or from PyPI (when published):
pip install weighted-randomizer
Usage
from randomizer import randomizer
# Create a randomizer with weighted items
items = {
"apple": 35.0,
"banana": 20.0,
"cherry": 45.0,
}
r = randomizer(items)
# Get a random item based on weights
selected = r.getRandom()
print(selected)
How It Works
The randomizer class normalizes weights to percentages (0-100), then uses cumulative weights to perform weighted random selection. Each item's probability of selection is proportional to its weight.
Example Output
percents sum to over 100, percents have been scaled accordingly.
apple # or banana, cherry based on weighted probability
License
MIT
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 weighted_randomizer-0.1.0.tar.gz.
File metadata
- Download URL: weighted_randomizer-0.1.0.tar.gz
- Upload date:
- Size: 3.1 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.13.0
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
37fbde09bc024ec82b3631ffcf0f82219601949d9b8213d108a8dec99318152c
|
|
| MD5 |
45a8538cc9af90d14ed2e7b089c8a688
|
|
| BLAKE2b-256 |
bdced2344eba53099057de5f607bc918e7669aa6e6e23fed2c38b4315292c0ee
|
File details
Details for the file weighted_randomizer-0.1.0-py3-none-any.whl.
File metadata
- Download URL: weighted_randomizer-0.1.0-py3-none-any.whl
- Upload date:
- Size: 3.8 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.13.0
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
3f4cbb33c9b02d1120cc77241ff9a84645b0d37af70f80d559eae894e8eee887
|
|
| MD5 |
82d729fcb5d009ee12aaaddbcf8b09f3
|
|
| BLAKE2b-256 |
5ecc609b62a64f278aee5cbc36d280e981dce006a67a10031c20b2cfe41c29be
|