PHPackages                             joshbruce/php-dice-bag - 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. joshbruce/php-dice-bag

Abandoned → [joshbruce/php-dice-tower](/?search=joshbruce%2Fphp-dice-tower)ArchivedLibrary[Utility &amp; Helpers](/categories/utility)

joshbruce/php-dice-bag
======================

A PHP library for rolling various dice and get various results

3.1.2(5y ago)034MITPHPPHP ~7

Since Oct 4Pushed 5y ago1 watchersCompare

[ Source](https://github.com/joshbruce/php-dice-bag)[ Packagist](https://packagist.org/packages/joshbruce/php-dice-bag)[ GitHub Sponsors](https://github.com/8fold)[ GitHub Sponsors](https://github.com/joshbruce)[ RSS](/packages/joshbruce-php-dice-bag/feed)WikiDiscussions master Synced today

READMEChangelog (6)Dependencies (2)Versions (7)Used By (0)

Dice Bag
========

[](#dice-bag)

A PHP library for "rolling" *n* dice, with *n* sides each.

Installation
------------

[](#installation)

```
composer require joshbruce/php-dice-bag

```

Usage
-----

[](#usage)

Say you are rolling a character for an RPG using a fairly standard method (4d6, drop the lowest).

```
DiceBag::roll4d6()->highest(3)->sum();
// step 1: [3, 5, 2, 1]
// step 2: [5, 3, 2]
// step 3: 10
```

You do not need to use the magic static method:

```
DiceBag::roll(4, 6)->highest(3)->sum();
// step 1: [3, 5, 2, 1]
// step 2: [5, 3, 2]
// step 3: 10
```

You can also roll a single die using one of the following:

```
DiceBag::roll();
// rolls 1d6

DiceBag::roll(1, 6);
// rolls 1d6

Dn::withSides();
// roll 1 die with the given number of sides
```

The values of the rolls are calculated at instantiation. Therefore, the various fluent methods are about manipulating the initial results or retrieving values from them.

Details
-------

[](#details)

Effectively this is a random number generator duplicating the feel and spread of physical dice. The minimum value is always 1.

Inspired by [AnyDice](https://anydice.com) and driven by the desire to create an [MORPG](https://en.wikipedia.org/wiki/Massively_multiplayer_online_role-playing_game) using various dice-based systems; specifically [7DSystem](http://www.7dsystem.com) and the [Cypher System](http://cypher-system.com).

Other
-----

[](#other)

See the .github directory for various details including code of conduct, constribution notes, and so on.

###  Health Score

26

—

LowBetter than 41% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity7

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity59

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 100% 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 ~4 days

Total

6

Last Release

2074d ago

Major Versions

1.0.0 → 2.0.02020-10-26

2.0.0 → 3.0.02020-10-26

### Community

Maintainers

![](https://www.gravatar.com/avatar/7787b6872cff33c6c0162d6cb4ee841c1a75adcce1b4d4efff759dbbf0d08d30?d=identicon)[itsjoshbruce](/maintainers/itsjoshbruce)

---

Top Contributors

[![joshbruce](https://avatars.githubusercontent.com/u/15252830?v=4)](https://github.com/joshbruce "joshbruce (10 commits)")

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/joshbruce-php-dice-bag/health.svg)

```
[![Health](https://phpackages.com/badges/joshbruce-php-dice-bag/health.svg)](https://phpackages.com/packages/joshbruce-php-dice-bag)
```

###  Alternatives

[dtm/dtm-client

A PHP coroutine client for distributed transaction manager DTM. 分布式事务管理器 DTM 的 PHP 协程客户端

34736.2k7](/packages/dtm-dtm-client)[igbinary/igbinary

Igbinary is a drop in replacement for the standard php serializer. Instead of the time and space consuming textual representation used by PHP's serialize(), igbinary stores php data structures in a compact binary form. Savings are significant when using memcached or similar memory based storages for serialized data.

7824.7k](/packages/igbinary-igbinary)

PHPackages © 2026

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