Skip to main content

DiceLib

A dice-rolling library for RPGs.

Requirements

  • Python 3.5 or newer.

Installation

pip install DiceLib

Usage

>>> from DiceLib import Die
>>> # You can create custom dice by specifying the number of faces:
... d6 = Die(6)
>>> # Rolling dice is simple:
... d6.roll()
[6]
>>> d6.roll(2)
[3, 5]
>>> d6.roll(7)
[2, 2, 6, 4, 4, 3, 1]
>>> # The value returned might look like a list, and in many way acts like one,
... # but it's actually a special class called Rolls:
... roll = _
>>> type(roll)
<class 'DiceLib.rolls.Rolls'>
>>> # Rolls act like lists in many ways:
... roll
[2, 2, 6, 4, 4, 3, 1]
>>> roll[1:3]
[2, 6]
>>> roll[1:3] = [5, 5]
>>> roll
[2, 5, 5, 4, 4, 3, 1]
>>> roll[0] = 6
>>> roll
[6, 5, 5, 4, 4, 3, 1]
>>> # But in other ways, Rolls are different:
... roll.total
28
>>> roll.count
7
>>> roll.highest
6
>>> roll.lowest
1
>>> roll[2:5].highest
5
>>> roll[2:5].total
13
>>> roll < 20
False
>>> roll > 20
True
>>> roll == 28
True
>>> int(roll)
28
>>> # You can easily add or subtract from a roll:
... roll + 2
30
... roll - 8
20
>>> # You can even drop the lowest or highest rolls:
... roll.drop_lowest()
[6, 5, 5, 4, 4, 3]
>>> roll.drop_lowest(3)
[6, 5, 5, 4]
>>> roll.drop_highest()
[5, 5, 4, 4, 3, 1]
>>> roll.drop_highest(3)
[4, 4, 3, 1]
>>> # Which makes it easy, for example, to roll stats:
... stats = dict()
>>> for stat in ["str", "dex", "con", "int", "wis", "cha"]:
...     stat_roll = int(d6.roll(4).drop_lowest())
...     stats[stat] = stat_roll
...
>>> stats
{'str': 12, 'dex': 15, 'con': 14, 'int': 12, 'wis': 15, 'cha': 11}

Release files for DiceLib 0.2.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for DiceLib 0.2.0
File Size Uploaded
DiceLib-0.2.0.tar.gz 3.0 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for DiceLib 0.2.0
File Interpreter ABI Platform
DiceLib-0.2.0-py3-none-any.whl Python 3 none any Details

Total release size: 7.4 kB

Release files / DiceLib-0.2.0.tar.gz

Download URL DiceLib-0.2.0.tar.gz
Size 3.0 kB
Tags Source
SHA-256 checksum
How to use checksums
ca782520bb21fab27753ae2b056270664327c2f77175c7bcda6700711918bd30
BLAKE2b-256 checksum
How to use checksums
b6b45a57b7d06933596f8bfa0a4e78019d146a1bd583752cf4ca4e45758dbd24
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/1.13.0 pkginfo/1.5.0.1 requests/2.21.0 setuptools/41.0.1 requests-toolbelt/0.9.1 tqdm/4.31.1 CPython/3.7.0

Release files / DiceLib-0.2.0-py3-none-any.whl

Download URL DiceLib-0.2.0-py3-none-any.whl
Size 4.4 kB
Tags Python 3
SHA-256 checksum
How to use checksums
65a9cca0cb1db2d8e99e06fd61206dbfc0f79cfbca78d7d755b74ce0dd8a49eb
BLAKE2b-256 checksum
How to use checksums
29d91931401cc9c1c01e2f5cb16f4d75068caa9a3279e40a64ec67ca7b5a0879
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/1.13.0 pkginfo/1.5.0.1 requests/2.21.0 setuptools/41.0.1 requests-toolbelt/0.9.1 tqdm/4.31.1 CPython/3.7.0

Release history Release notifications | RSS feed

This release

0.2.0 This release

2 release files

0.1.0

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page