API

Through out this documentation the work unit is used to refer to the current type you are look at. When you import dicehancis you get the following imported

dicechanics.d(inpt, **kwards)

Function that creates a die from various input types Currently takes int, str, Iterable, Die which it copies, and a dict

Parameters:
  • inpt (Iterable | Int | Die | dict) – the input for the function

  • **kwards – Rounding: Callable

Returns:

out – The die created from the input

Return type:

Die

dicechanics.z(inpt, **kwards)

Function that creates a z-die from various input types

A z-die is a die which starts from 0. So a z9 is a die going from [0..9]

Parameters:

inpt (int) – the input for the function

Returns:

out – The die created from the input

Return type:

Die

dicechanics.pool(inpt)

Creates a pool from a list of number and/or dice.

Parameters:

inpt (list) – list of numbers or dice

Returns:

out – The pool containing the elements of the input

Return type:

Pool

dicechanics.d4

A 4 sided die

dicechanics.d6

A 6 sided die

dicechanics.d8

A 8 sided die

dicechanics.d10

A 10 sided die

dicechanics.d12

A 12 sided die

dicechanics.d20

A 20 sided die

dicechanics.d100

A 100 sided die

dicechanics.z9

A 10 sided die with values [0..9]

class dicechanics.Die

The class that represents a statistical presentation of a die.

__add__(rhs)

Return self + value

__call__(mapping)

Used to wrap the unit in as decorator. It used the map function.

Parameters:

func – The function to wrap.

Returns:

out – A function that returns a unit of the mapped function

Return type:

callable

__eq__(rhs)

Return self == value

__ge__(rhs)

Return self => value

__gt__(rhs)

Return self > value

__init__(data=None, /, **kwargs)

Initializes the unit, its recommended to use d() interface.

Parameters:

data (dict) – A dict as input

__lt__(rhs)

Return self < value

__matmul__(rhs)

Return self @ rhs

__mul__(rhs)

Return value * self

__ne__(rhs)

Return self != value

__neg__()

Return -self

__radd__(lhs)

Return value + self

__rmatmul__(lhs)

Return lhs @ self

__rmul__(lhs)

Return self / value

__rsub__(lhs)

Return value - self

__sub__(rhs)

Return self - value

__truediv__(rhs)

Return self / value

clear()

clears the unit.

functions like dict.clear()

copy()

Function that creates a copy of the unit

Returns:

out – The copy

Return type:

type(self)

count(*targets)

Function that counts the given number of outcomes, results in a binary unit

Parameters:

count (args) – The faces we want to count

Returns:

out – The unit representing the operation

Return type:

type(self)

explode(*exploder, depth=1)

Function that explodes the units outcomes.

Parameters:
  • *exploder – The numbers that need to be rerolled

  • depth (int) – How many times do we reroll

Returns:

out – A unit representing the operation

Return type:

type(self)

extend(iterable, /)

Extends the underlying dict.

functions like dict.extend

fold_over(rhs, /, into=None)

Function that folds values over @rhs and puts them into @into

Parameters:
  • rhs (object) – The object we compare in relation to

  • into (object) – Where we store the evaluated numbers

Returns:

out – The new unit that with the values folded into @into

Return type:

type(self)

fold_under(rhs, /, into=None)

Function that folds values under @rhs and puts them into @into

Parameters:
  • rhs (object) – The object we compare in relation to

  • into (object) – Where we store the evaluated numbers

Returns:

out – The new unit that with the values folded into @into

Return type:

type(self)

implode(*imploder, depth=1)

Function that implodes the unit outcomes.

Parameters:
  • *imploder – The numbers that need to be rerolled

  • depth (int) – How many times do we reroll

Returns:

out – A unit representing the operation

Return type:

type(self)

items()

returns an iterator for (keys, items) for the underlying dict.

functions like dict.items()

keys()

returns an iterator for (key) for the underlying dict.

functions like dict.items()

map(mapping)

Maps a function onto the die

Parameters:

func (Callable) – The function to be mapped

Returns:

out – The die with the results of the mapping

Return type:

type(self)

pop(index=-1, /)

pops the value for the given index

Functions like a dict.pop

popitem()

pops the set of (key, item)

Functions like a dict.popitem

reroll(*redo, depth=1)

Function that rerolls on a given set of values

Parameters:
  • *redo – Faces to reroll

  • depth (int | str) – the number of rerolls allowed. “Inf” as a string for an infinite amount of times

  • Returns

  • out (Die) – A die that represents the rerolled probabilities

  • -------

simplify()

Function that simplifies the counts of the unit outcomes.

sort()

Function that sorts a the unit outcomes

update(other=None, **kwargs)

updates the underlying dict.

functions like dict.update

values() an object providing a view on D's values
property c

Returns the count list of the unit.

Returns:

out – The number pr face of the unit.

Return type:

list

property cdf

Returns the cumulative probability of the die

Returns:

out – The cumulative probability for the outcomes.

Return type:

List

property counts

Returns the count list of the unit.

Returns:

out – The number pr face of the unit.

Return type:

list

property f

Mirror for self.outcomes, that translates outcomes to faces

property faces

Mirror for self.outcomes, that translates outcomes to faces

property max

Returns the maximum face of the unit.

Parameters:

out (float) – The maximum face of the unit.

property mean

Returns the mean of the unit

Returns:

out – The mean of the unit.

Return type:

Number

property min

Returns the minimum faces of the unit

Parameters:

out (Number | None) – The minimum face of the unit

property o

Returns the outcomes of the unit

Returns:

out – The outcomes of the unit.

Return type:

list

property outcomes

Returns the outcomes of the unit

Returns:

out – The outcomes of the unit.

Return type:

list

property p

Returns the probability for the outcomes

Returns:

out – The probability of the outcomes.

Return type:

List

property probability

Returns the probability for the outcomes

Returns:

out – The probability of the outcomes.

Return type:

List

property std

Returns the standard deviation of the unit

Returns:

out – The standard deviations of the unit.

Return type:

Number

property variance

Returns the variance of the unit

Returns:

out – The variance of the unit.

Return type:

Number

class dicechanics.Pool

Class that represents a pool of dice.

__init__(dice)

Initializes the pool.It is recommend to use pool() interface.

Parameters:

dice (list)

perform(func)

Function that applies a given function to the elements in the pool. The function must have the form f(x, y) -> z, and its operation must be linear, ie. the order in which the values are calculated doesn’t matter.

Parameters:

func (Callable) – Function with the form f(x, y) -> z. It must apply a linear operation

Return type:

Die

copy()

Function that creates a copy of the pool

Returns:

out – A copy of the current pool

Return type:

Pool

__getitem__(idx)

Get in this function defines which faces in sorted outcomes of rolling the back needs to be selected and operated on in the perform method

Parameters:

idx (list | slice)

Returns:

out – A pool copy with which die to keep set

Return type:

pool

__call__(func)

A wrapper for perform, allows the pool to be used as a decorator

__add__(rhs)

Return self + value