Skip to main content

Train's Dice Stats Package

Project description

A simple dice roll probability package inspired by anydice.com. There are many like it, but this one is mine.

Usage

Dice rolls use the dice_roll class. The most basic dice roll is consist of a number of dice and a number of sides. For example, to roll three six sided dice or 3d6:

dnd = dice_roll((3,6))

You can drop the lowest rolls by using the drop option. So, to get the 4d6 drop lowest D&D stat roll

dndDrop = dice_roll((4,6),drop=1)
print(dnd)
             pmf       cmf
domain                    
3       0.000611  0.000611
4       0.001833  0.002443
5       0.003665  0.006109
6       0.008312  0.014421
7       0.015774  0.030195
8       0.026050  0.056245
9       0.041685  0.097930
10      0.062678  0.160608
11      0.082418  0.243026
12      0.108365  0.351391
13      0.127389  0.478780
14      0.139489  0.618268
15      0.135985  0.754254
16      0.123489  0.877743
17      0.079540  0.957283
18      0.042717  1.000000

We can also apply a function to the dice roll afterwards. This can be done in the dice_roll constructor or with the apply_function method. For example, we can get the D&D stat modifier distribution

dndDrop_modifiers = dnd.apply_function(lambda x: (x-10)//2)

Note, the function is always cast to an integer.

You can plot the distribution with the plot method.

dndDrop_modifiers.plot(title="4d6 Drop Lowest Stat Modifiers")

4d6 Drop Lowest Stat Modifiers Plot

dice_roll supports mean, median, and mode.

[dndDrop_modifiers.mean,dndDrop_modifiers.median,dndDrop_modifiers.mode]
[1.4318137860082305, 2, 2]

Quantiles are also availible with the quantile method.

dndDrop_modifiers.quantile([.05,.95])
array([-1,  3])

You can add and subtract any two dice_roll distributions.

dice_roll((1,6))+dice_roll((1,6))-dice_roll((2,6))
             pmf       cmf
domain                    
-10     0.000772  0.000772
-9      0.003086  0.003858
-8      0.007716  0.011574
-7      0.015432  0.027006
-6      0.027006  0.054012
-5      0.043210  0.097222
-4      0.061728  0.158951
-3      0.080247  0.239198
-2      0.096451  0.335648
-1      0.108025  0.443673
 0      0.112654  0.556327
 1      0.108025  0.664352
 2      0.096451  0.760802
 3      0.080247  0.841049
 4      0.061728  0.902778
 5      0.043210  0.945988
 6      0.027006  0.972994
 7      0.015432  0.988426
 8      0.007716  0.996142
 9      0.003086  0.999228
 10     0.000772  1.000000

You can compute the sum of a sample of size k from a dice_roll object using thr sum method. This supports dropping the lowest roll.

dndDrop.sum(6,drop=2).plot(title="D&D Stat Array Total Modifiers with Two Dump Stats")

D&D Stat Array Total Modifiers with Two Dump

Lastly, you can export the table of support, pmf and cmf to a Pandas datafram with the df method.

dndDrop_modifiers.df

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

dice_roll-0.1.1.tar.gz (2.6 kB view details)

Uploaded Source

Built Distribution

dice_roll-0.1.1-py3-none-any.whl (2.4 kB view details)

Uploaded Python 3

File details

Details for the file dice_roll-0.1.1.tar.gz.

File metadata

  • Download URL: dice_roll-0.1.1.tar.gz
  • Upload date:
  • Size: 2.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.8.18

File hashes

Hashes for dice_roll-0.1.1.tar.gz
Algorithm Hash digest
SHA256 7103f30bcc30d66df01a12d23d66da31f317c08f14d3827aa53782767db0554b
MD5 5c661cc506141ad51a70e3ff8c4239d5
BLAKE2b-256 f3f45c93660a709d98e476932b9554d6b096f52c102520ede4cddc59183d34d3

See more details on using hashes here.

File details

Details for the file dice_roll-0.1.1-py3-none-any.whl.

File metadata

  • Download URL: dice_roll-0.1.1-py3-none-any.whl
  • Upload date:
  • Size: 2.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.8.18

File hashes

Hashes for dice_roll-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 392faaba11fda958e3246dfa5206fcb1da66e75a45aa44c2ffb7d822e6899947
MD5 0117d362c4f508e8cd29efb7fb4e7183
BLAKE2b-256 5465b9b7a339adbb3d87ee8ecd4e9a38db8ece4929eaf2c83149ce64cc373cd9

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