PHPackages                             ringmaster/dicecalc - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Utility &amp; Helpers](/categories/utility)
4. /
5. ringmaster/dicecalc

ActiveLibrary[Utility &amp; Helpers](/categories/utility)

ringmaster/dicecalc
===================

DiceCalc

241711PHP

Since Nov 4Pushed 9y ago4 watchersCompare

[ Source](https://github.com/ringmaster/dicecalc)[ Packagist](https://packagist.org/packages/ringmaster/dicecalc)[ RSS](/packages/ringmaster-dicecalc/feed)WikiDiscussions master Synced 6d ago

READMEChangelogDependenciesVersions (2)Used By (0)

DiceCalc
========

[](#dicecalc)

Project status
--------------

[](#project-status)

[![https://travis-ci.org/ringmaster/dicecalc.svg?branch=master](https://camo.githubusercontent.com/149a72be43e9f166c6115100ae960849e32c33fcde7587e5ffca95c1fd9d11ec/68747470733a2f2f7472617669732d63692e6f72672f72696e676d61737465722f6469636563616c632e7376673f6272616e63683d6d6173746572)](https://travis-ci.org/ringmaster/dicecalc)[![https://scrutinizer-ci.com/g/ringmaster/dicecalc/badges/quality-score.png?b=master](https://camo.githubusercontent.com/a5f85e109fadd13271af85f69d214615eaa07e1abda6d40171aec661fe05817e/68747470733a2f2f7363727574696e697a65722d63692e636f6d2f672f72696e676d61737465722f6469636563616c632f6261646765732f7175616c6974792d73636f72652e706e673f623d6d6173746572)](https://scrutinizer-ci.com/g/ringmaster/dicecalc/?branch=master)How to use
----------

[](#how-to-use)

Create a new Calc class, and pass the dice expression to the constructor::$calc = new Calc($expression);Output the interpretation of the roll::echo $calc-&gt;infix();Output the result of the roll::echo $calc();Dice Expressions
----------------

[](#dice-expressions)

The basic expression is to use a "d" followed by the number of sides of the die to roll.

*Examples:*

d6roll a six-sided died20roll a twenty-sided died%roll a percentile (1-100) diedfroll a fudge (-1, 0, 1) dieTo roll multiple of the same sided die, prefix the die type with a multiplier number.

*Examples:*

3d6roll d6 three times, sum the result2d20roll d20 twice, sum the result6dfroll six fudge dice, sum the resultBasic math operations are possible as expressions.

*Examples:*

4+4Add 4+44\*5Multiply 4\*54+4\*5Multiply 4\*5, then add 4 (order of operations is obeyed)(4+4)\*5Add 4+4, then multiply by 5Math on sets of numbers.

*Examples:*

2\*\[3,4\]Multiply 2\*3 and 2\*4, resulting in a set \[6,8\]\[1,2\]\*\[3,4\]Multiply these sets together, resulting in a nested set \[\[3,4\],\[6,8\]\]Any combination of dice or constants in an expressions.

*Examples:*

2d6+4roll 2d6, sum the dice and add 43d8-5roll 3d8, sum the dice and subtract 52d4+d6roll 2d4 and d6, sum all the diceEvaluate whether a result meets a certain condition or target number.

*Examples:*

4+4 &gt; 7returns true, because 4+4 is greater than 75d6 &gt; 5returns true, because 5d6 is always greater than 5d20+4 &gt; 12simulates a d20 system skill value of 4 compared to a target number of 12Produce a set of rolls by surrounding the roll with brackets and prefixing with a multiplier.

*Examples:*

6\[3d6\]produces a set of 6 numbers created by rolling 3d64\[d%\]produces a set of 4 numbers created by rolling percentileRoll a custom die by specifying the dice sides in brackets after the "d".

*Examples:*

d\[1,2,2,3,3,4\]Roll a six-sided die with custom numeric facesd\[red,green,blue\]Roll a three-sided die with colored facesKeep only the dice in an individual roll that meet specific conditions by applying the "k" postfix.

*Examples:*

5d6 keep &gt; 4Role five six-sided dice, keep only the dice that are greater than 4, sum the kept dice5d6k&gt;4same as above6d8 keep &lt; 4Roll six eight-sided dice, keep only the dice that are less than 4, sum the kept dice6d8k&lt;4same as aboveKeep only the dice that are the lowest or highest values rolled.

*Examples:*

4d6 highest 3Roll 4d6, keep only the highest 3 dice4d6h3same as above2s20 lowest 1Roll 2d20, keep only the lowest die2d20l1same as aboveReroll dice that do not meet certain conditions.

*Examples:*

3d6 reroll &lt; 3Roll 3d6, reroll any die that is less than 33d6r&lt;3same as above2d% reroll &lt; 40Roll 2d%, reroll any die that is less than 402d%r&lt;40same as aboveOur stupid way of rolling D&amp;D character stats.

*Examples:*

4d6r&lt;3h3Roll 4d6, reroll any die that is less than 3, keep the highest 3 dice, sum the kept diceProduce open-ended dice using the "o" prefix.

*Examples:*

4d6o=6Roll 4d6. When any die lands on 6, roll that die again and add the result to that die. Sum all die totals.A stupid example nobody would ever use, I hope:

3d6r&lt;4o=6k&gt;6Roll 3d6. Reroll any die less than 4. When any die is a 6, reroll and add the new value to the original one. Sum the die totals of only those dice that are greater than 6.Future Enhancements
-------------------

[](#future-enhancements)

- Better group handling
- Better custom die handling
- Variable replacements (To handle rolls like: d20 + $str\_bonus &gt; $target )
- Range violation exceptions (d6k&lt;0)
- Non-text output method

###  Health Score

26

—

LowBetter than 43% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity18

Limited adoption so far

Community15

Small or concentrated contributor base

Maturity43

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 75.5% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

### Community

Maintainers

![](https://www.gravatar.com/avatar/cb2df7166a52356740ed1e6c8d180ae30dee8a2c4860240c283fb0edd678afa7?d=identicon)[wulfheart](/maintainers/wulfheart)

---

Top Contributors

[![sergej-kurakin](https://avatars.githubusercontent.com/u/196096?v=4)](https://github.com/sergej-kurakin "sergej-kurakin (37 commits)")[![ringmaster](https://avatars.githubusercontent.com/u/127738?v=4)](https://github.com/ringmaster "ringmaster (12 commits)")

### Embed Badge

![Health badge](/badges/ringmaster-dicecalc/health.svg)

```
[![Health](https://phpackages.com/badges/ringmaster-dicecalc/health.svg)](https://phpackages.com/packages/ringmaster-dicecalc)
```

###  Alternatives

[summerblue/generator

Extend Laravel's generators scaffold.

34139.9k](/packages/summerblue-generator)[husseinalhammad/fontawesome-svg

PHP class to add Font Awesome 5+'s SVG icons inline without Javascript.

1811.3k](/packages/husseinalhammad-fontawesome-svg)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
