Skip to content
Python module implementing Weighted Random http://weighted-random.github.com/wr
Python
Find file
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Failed to load latest commit information.
docs
tests
.gitignore
.travis.yml
LICENSE
MANIFEST.in
README.rst
setup.py
tox.ini
wr.py

README.rst

http://www.flickr.com/photos/vj-dipsy/4297831216/

wr (Weighted Random)

wr is a weighted random implementation in Python.

wr.choice can be fed with a mapping (such as dictionaries) containing a returnable (what to return) and a integer representing their respective weight. The key can be anything hashable but the weight must be a integer.

Optionally you may feed wr.choice with a sequence of pairs.

Documentation

Documentation is available at http://wr.readthedocs.org/

Example

>>> import wr

>>> data = {'cat': 60, 'dog': 30, 'bird': 10}
>>> animal = wr.choice(data)
>>> print animal
cat # well, the cat had a good 60% shot at it.

Installation

Install wr with pip install wr or just download wr.py and place it in your project directory.

License

BSD

Something went wrong with that request. Please try again.