dice-roll


Namedice-roll JSON
Version 0.1.1 PyPI version JSON
download
home_pagehttps://github.com/jtrainrva/dice_roller
SummaryTrain's Dice Stats Package
upload_time2024-01-24 05:40:41
maintainer
docs_urlNone
authorJoseph Burris
requires_python>=3.8
license
keywords python dice
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            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](https://github.com/jtrainrva/dice_roller/blob/main/dndarray_modifiers.png?raw=True)

`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](https://github.com/jtrainrva/dice_roller/blob/main/dndarray_modifiers_dumpstats.png?raw=True)

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

```
dndDrop_modifiers.df
```

            

Raw data

            {
    "_id": null,
    "home_page": "https://github.com/jtrainrva/dice_roller",
    "name": "dice-roll",
    "maintainer": "",
    "docs_url": null,
    "requires_python": ">=3.8",
    "maintainer_email": "",
    "keywords": "python,dice",
    "author": "Joseph Burris",
    "author_email": "jtrainrva@gmail.com",
    "download_url": "https://files.pythonhosted.org/packages/f3/f4/5c93660a709d98e476932b9554d6b096f52c102520ede4cddc59183d34d3/dice_roll-0.1.1.tar.gz",
    "platform": null,
    "description": "A simple dice roll probability package inspired by anydice.com. There are many like it, but this one is mine.\n\n# Usage\n\nDice 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:\n\n```\ndnd = dice_roll((3,6))\n```\n\nYou can drop the lowest rolls by using the drop option. So, to get the 4d6 drop lowest D&D stat roll\n\n```\ndndDrop = dice_roll((4,6),drop=1)\nprint(dnd)\n```\n\n```\n             pmf       cmf\ndomain                    \n3       0.000611  0.000611\n4       0.001833  0.002443\n5       0.003665  0.006109\n6       0.008312  0.014421\n7       0.015774  0.030195\n8       0.026050  0.056245\n9       0.041685  0.097930\n10      0.062678  0.160608\n11      0.082418  0.243026\n12      0.108365  0.351391\n13      0.127389  0.478780\n14      0.139489  0.618268\n15      0.135985  0.754254\n16      0.123489  0.877743\n17      0.079540  0.957283\n18      0.042717  1.000000\n```\n\nWe 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\n\n```\ndndDrop_modifiers = dnd.apply_function(lambda x: (x-10)//2)\n```\nNote, the function is always cast to an integer.\n\nYou can plot the distribution with the `plot` method.\n\n```\ndndDrop_modifiers.plot(title=\"4d6 Drop Lowest Stat Modifiers\")\n```\n\n![4d6 Drop Lowest Stat Modifiers Plot](https://github.com/jtrainrva/dice_roller/blob/main/dndarray_modifiers.png?raw=True)\n\n`dice_roll` supports mean, median, and mode.\n\n```\n[dndDrop_modifiers.mean,dndDrop_modifiers.median,dndDrop_modifiers.mode]\n```\n\n```\n[1.4318137860082305, 2, 2]\n```\n\nQuantiles are also availible with the `quantile` method.\n\n```\ndndDrop_modifiers.quantile([.05,.95])\n```\n\n```\narray([-1,  3])\n```\n\nYou can add and subtract any two dice_roll distributions.\n\n```\ndice_roll((1,6))+dice_roll((1,6))-dice_roll((2,6))\n```\n\n```\n             pmf       cmf\ndomain                    \n-10     0.000772  0.000772\n-9      0.003086  0.003858\n-8      0.007716  0.011574\n-7      0.015432  0.027006\n-6      0.027006  0.054012\n-5      0.043210  0.097222\n-4      0.061728  0.158951\n-3      0.080247  0.239198\n-2      0.096451  0.335648\n-1      0.108025  0.443673\n 0      0.112654  0.556327\n 1      0.108025  0.664352\n 2      0.096451  0.760802\n 3      0.080247  0.841049\n 4      0.061728  0.902778\n 5      0.043210  0.945988\n 6      0.027006  0.972994\n 7      0.015432  0.988426\n 8      0.007716  0.996142\n 9      0.003086  0.999228\n 10     0.000772  1.000000\n```\n\nYou 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.\n\n```\ndndDrop.sum(6,drop=2).plot(title=\"D&D Stat Array Total Modifiers with Two Dump Stats\")\n```\n\n![D&D Stat Array Total Modifiers with Two Dump](https://github.com/jtrainrva/dice_roller/blob/main/dndarray_modifiers_dumpstats.png?raw=True)\n\nLastly, you can export the table of support, pmf and cmf to a Pandas datafram with the `df` method.\n\n```\ndndDrop_modifiers.df\n```\n",
    "bugtrack_url": null,
    "license": "",
    "summary": "Train's Dice Stats Package",
    "version": "0.1.1",
    "project_urls": {
        "Homepage": "https://github.com/jtrainrva/dice_roller"
    },
    "split_keywords": [
        "python",
        "dice"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "5465b9b7a339adbb3d87ee8ecd4e9a38db8ece4929eaf2c83149ce64cc373cd9",
                "md5": "0117d362c4f508e8cd29efb7fb4e7183",
                "sha256": "392faaba11fda958e3246dfa5206fcb1da66e75a45aa44c2ffb7d822e6899947"
            },
            "downloads": -1,
            "filename": "dice_roll-0.1.1-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "0117d362c4f508e8cd29efb7fb4e7183",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.8",
            "size": 2433,
            "upload_time": "2024-01-24T05:40:40",
            "upload_time_iso_8601": "2024-01-24T05:40:40.089482Z",
            "url": "https://files.pythonhosted.org/packages/54/65/b9b7a339adbb3d87ee8ecd4e9a38db8ece4929eaf2c83149ce64cc373cd9/dice_roll-0.1.1-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "f3f45c93660a709d98e476932b9554d6b096f52c102520ede4cddc59183d34d3",
                "md5": "5c661cc506141ad51a70e3ff8c4239d5",
                "sha256": "7103f30bcc30d66df01a12d23d66da31f317c08f14d3827aa53782767db0554b"
            },
            "downloads": -1,
            "filename": "dice_roll-0.1.1.tar.gz",
            "has_sig": false,
            "md5_digest": "5c661cc506141ad51a70e3ff8c4239d5",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.8",
            "size": 2565,
            "upload_time": "2024-01-24T05:40:41",
            "upload_time_iso_8601": "2024-01-24T05:40:41.736123Z",
            "url": "https://files.pythonhosted.org/packages/f3/f4/5c93660a709d98e476932b9554d6b096f52c102520ede4cddc59183d34d3/dice_roll-0.1.1.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2024-01-24 05:40:41",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "jtrainrva",
    "github_project": "dice_roller",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": false,
    "requirements": [],
    "lcname": "dice-roll"
}
        
Elapsed time: 0.17308s