PHPackages                             sergej-kurakin/diceroller - 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. sergej-kurakin/diceroller

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

sergej-kurakin/diceroller
=========================

Dice Roller, PSR compatible fork from https://github.com/ringmaster/dicecalc

2.0.0(9y ago)14.4k↓20%MITPHPPHP &gt;=5.4

Since Sep 28Pushed 9y agoCompare

[ Source](https://github.com/sergej-kurakin/dicecalc)[ Packagist](https://packagist.org/packages/sergej-kurakin/diceroller)[ RSS](/packages/sergej-kurakin-diceroller/feed)WikiDiscussions master Synced 1mo ago

READMEChangelogDependencies (9)Versions (5)Used By (0)

DiceCalc
========

[](#dicecalc)

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

[](#project-status)

[![https://travis-ci.org/sergej-kurakin/dicecalc.svg?branch=master](https://camo.githubusercontent.com/1ab1361684737452734b5019498ee70bac1dc0655fd29caefffeafe5cad5e396/68747470733a2f2f7472617669732d63692e6f72672f73657267656a2d6b7572616b696e2f6469636563616c632e7376673f6272616e63683d6d6173746572)](https://travis-ci.org/sergej-kurakin/dicecalc)[![https://scrutinizer-ci.com/g/sergej-kurakin/dicecalc/badges/quality-score.png?b=master](https://camo.githubusercontent.com/ce65251a27989c9d94b2815f69a940879fa19f27a273d0c176cbcbc231f31717/68747470733a2f2f7363727574696e697a65722d63692e636f6d2f672f73657267656a2d6b7572616b696e2f6469636563616c632f6261646765732f7175616c6974792d73636f72652e706e673f623d6d6173746572)](https://scrutinizer-ci.com/g/sergej-kurakin/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

32

—

LowBetter than 72% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity24

Limited adoption so far

Community8

Small or concentrated contributor base

Maturity61

Established project with proven stability

 Bus Factor1

Top contributor holds 82.8% 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.

###  Release Activity

Cadence

Every ~609 days

Total

2

Last Release

3636d ago

Major Versions

1.0.0 → 2.0.02016-05-29

PHP version history (2 changes)1.0.0PHP &gt;=5.3.3

2.0.0PHP &gt;=5.4

### Community

Maintainers

![](https://www.gravatar.com/avatar/bc0694c874fce1a306d5424fab96058eb35876465f4b3d0f7d793925d1dca8d3?d=identicon)[sergej-kurakin](/maintainers/sergej-kurakin)

---

Top Contributors

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

---

Tags

dicedice calcdice calculatordice roller

###  Code Quality

TestsPHPUnit

Code StylePHP CS Fixer

### Embed Badge

![Health badge](/badges/sergej-kurakin-diceroller/health.svg)

```
[![Health](https://phpackages.com/badges/sergej-kurakin-diceroller/health.svg)](https://phpackages.com/packages/sergej-kurakin-diceroller)
```

###  Alternatives

[grrr-amsterdam/garp-functional

Utility library embracing functional programming paradigms.

32116.1k5](/packages/grrr-amsterdam-garp-functional)

PHPackages © 2026

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