Skip to main content

A library for parsing and evaluating dice notation

Project description

Latest PyPI version Travis-CI build status

A library and command line tool for parsing and evaluating dice notation.

Usage

From the command line:

roll 3d6

From python:

import dice
dice.roll('3d6')

Notation

The expression works like a simple equation parser with some extra operators.

The following operators are listed in order of precedence.

The dice (‘d’) operator takes an amount (A) and a number of sides (S), and returns a list of A random numbers between 1 and S. For example: 4d6 may return [6, 3, 2, 4].

If A is not specified, it is assumed you want to roll a single die. d6 is equivalent to 1d6.

Basic integer operations are available: 16 / 8 * 4 + 2 - 1 -> 9.

A set of rolls can be turned into an integer with the total (t) operator. 6d1t will return 6 instead of [1, 1, 1, 1, 1, 1]. Applying integer operations to a list of rolls will total them automatically.

A set of dice rolls can be sorted with the sort (s) operator. 4d6s will not change the return value, but the dice will be sorted from lowest to highest.

The lowest or highest rolls can be selected with ^ and v. 6d6^3 will keep the highest 3 rolls, whereas 6d6v3 will select the lowest 3 rolls.

Licence

The MIT License (MIT)

Copyright (c) 2013 Sam Clements

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the “Software”), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

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-1.0.3.tar.gz (7.5 kB view details)

Uploaded Source

Built Distribution

dice-1.0.3-py2.py3-none-any.whl (12.4 kB view details)

Uploaded Python 2 Python 3

File details

Details for the file dice-1.0.3.tar.gz.

File metadata

  • Download URL: dice-1.0.3.tar.gz
  • Upload date:
  • Size: 7.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No

File hashes

Hashes for dice-1.0.3.tar.gz
Algorithm Hash digest
SHA256 8e2ab0aa3d612522e9deec82117d95a108097d204ce2b181463345d9ecf1ae63
MD5 810d564701ffa4f35db9fb564f0c8a5f
BLAKE2b-256 bd3132308c5331c93a3e2371b9d85b4b389943d63b257744dacbfae4035b320a

See more details on using hashes here.

File details

Details for the file dice-1.0.3-py2.py3-none-any.whl.

File metadata

File hashes

Hashes for dice-1.0.3-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 7beb7b652b2feafb821816e40df98c3e88beb23695929238cfd1e9c3a164e85a
MD5 14f845a45560906c2f6250ae72bfe019
BLAKE2b-256 3eda2ab612d882fb7aab125349ddd705d05edcbf1f84edfd119e0e97c4f64feb

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