Skip to content
🎲 Using dice in a Pythonic way
Python
Branch: master
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
dragn Added autogeneration of dice at request Sep 29, 2019
.codacy.yml
.flake8
.gitignore Initial commit Mar 10, 2013
.travis.yml Add mypy check to travis CI Sep 29, 2019
LICENSE
MANIFEST.in Added MANIFEST.in Nov 3, 2018
README.md Bump to version v0.3.0 Jun 29, 2019
dragn_logo.png Add logo to README.md Jun 20, 2019
mypy.ini
setup.py Bump to version 0.4 Sep 29, 2019

README.md

Dragn Logo

Supported Python versions PyPI version Build Status Codecoverage Licence Code style: Black Downloads


Roll dice in your python programs


Why?

I wanted a better API to rolling dice using Python, and the usual random.randint is very good, but doesn't really represent rolling dice quite the way I imagine it.

This was a good learning experiment, but I'm not expecting anyone to use it.

Who is this for?

People building RPGs, or games that would involve dice and who care about how their code looks like.

I may be biased, but I really believe that this library provides a much better interface than pure random.randint.

How to install

$ pip install dragn

How to use

>> from dragn.dice import D4, D6, D8
>>> D6()
1
>>> f"You roll the die and the result is {D8()}"
'You roll the die and the result is 4'
>>> f"You roll 3 dice and you get {[D8() for _ in range(3)]}"
>>> 'You roll 3 dice and you get [3, 1, 8]'
>>> four_dice = D4 * 4
>>> f"You roll 4 dice and the results are {four_dice()}"
'You roll 4 dice and the results are (4, 3, 1, 2)'
>>> f"You roll two dice and the results are {two_dice()}"
'You roll two dice and the results are (3, 4)'
>>> dice_tower = (D6 * 2) + D4
>>> f"You roll two D6 and a D4 and check the results {dice_tower()}"
'You roll two D6 and a D4 and check the results (2, 2, 6)'

For more examples, check the tests

You can’t perform that action at this time.