Skip to main content

A package for computing dice probabilities

Project description

A Python library for computing dice probabilities.

Installing

pip install hdroller

Features

  • Implemented in pure Python for high interoperability.
  • Weights are Python ints, providing exact results even for large numbers of dice.
  • Dice support all standard operators as well as an extensive library of functions.
  • Dice pool system allows for flexible yet efficient solutions to common problems.
  • Also handles multivariate distributions (though less tested).

API documentation

GitLab.

Examples

JupyterLite notebooks

See this JupyterLite distribution for a collection of interactive examples.

Applications

Advanced Dungeons & Dragons 1st edition ability score methods

Source for these methods.

Method I:

All scores are recorded and arranged in the order the player desires. 4d6 are rolled, and the lowest die (or one of the lower) is discarded.

Method II:

All scores are recorded and arranged as in Method I. 3d6 are rolled 12 times and the highest 6 scores are retained.

Method III:

Scores rolled are according to each ability category, in order, STRENGTH, INTELLIGENCE, WISDOM, DEXTERITY, CONSTITUTION, CHARISMA. 3d6 are rolled 6 times for each ability, and the highest score in each category is retained for that category.

Method IV:

3d6 are rolled sufficient times to generate the 6 ability scores, in order, for 12 characters. The player then selects the single set of scores which he or she finds most desirable and these scores are noted on the character record sheet.

import hdroller

"""
The @ operator means "roll the left die, then roll that many of the right die and sum".
Integers are treated as a die that always rolls that number.
Therefore:
* 3 @ hdroller.d6 means 3d6.
* hdroller.d6 @ 3 means roll a d6 and multiply the result by 3.
"""

method1 = 6 @ hdroller.d6.keep_highest(num_dice=4, num_keep=3)
method2 = (3 @ hdroller.d6).keep_highest(12, 6)
# num_keep defaults to 1.
method3 = 6 @ (3 @ hdroller.d6).keep_highest(6)
method4 = (6 @ (3 @ hdroller.d6)).keep_highest(12)

import numpy
import matplotlib.pyplot as plt

fig, ax = plt.subplots()
ax.plot(method1.outcomes(), method1.pmf(percent=True))
ax.plot(method2.outcomes(), method2.pmf(percent=True))
ax.plot(method3.outcomes(), method3.pmf(percent=True))
ax.plot(method4.outcomes(), method4.pmf(percent=True))
ax.set_title('AD&D 1e ability score methods')
ax.legend(['Method I', 'Method II', 'Method III', 'Method IV'])
ax.set_xlabel('Total of ability scores')
ax.set_xlim(50, 100)
ax.set_ylim(0)
ax.grid(True)
plt.show()

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

hdroller-0.6.7.tar.gz (30.8 kB view details)

Uploaded Source

Built Distribution

hdroller-0.6.7-py3-none-any.whl (34.9 kB view details)

Uploaded Python 3

File details

Details for the file hdroller-0.6.7.tar.gz.

File metadata

  • Download URL: hdroller-0.6.7.tar.gz
  • Upload date:
  • Size: 30.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.2 importlib_metadata/4.8.1 pkginfo/1.7.1 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.62.2 CPython/3.9.10

File hashes

Hashes for hdroller-0.6.7.tar.gz
Algorithm Hash digest
SHA256 2f3ed087bc300a445e03d5cb553703b594357faea54c5beee9dbf9ed2d24228c
MD5 a8fc350b13cd6d4b1fea562e275d695f
BLAKE2b-256 b457d6a9a54f7c21369d3e873b1901729214466f0cc5cb33e611bd2e0c7ed923

See more details on using hashes here.

File details

Details for the file hdroller-0.6.7-py3-none-any.whl.

File metadata

  • Download URL: hdroller-0.6.7-py3-none-any.whl
  • Upload date:
  • Size: 34.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.2 importlib_metadata/4.8.1 pkginfo/1.7.1 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.62.2 CPython/3.9.10

File hashes

Hashes for hdroller-0.6.7-py3-none-any.whl
Algorithm Hash digest
SHA256 4042a8e53f8e5165ca6da9e8824f488cf15b44531c8de8cc89c3d6ea627c902b
MD5 9fb616e294c0befd154c6d3913f611ca
BLAKE2b-256 e6162cfdbb1fc6135bb6565711c8787bf29fbff3d2dc7ac7818e36944b2c478e

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page