Skip to content

Introduction ​

RPG Dice Roller is a JavaScript and TypeScript library for rolling dice using familiar tabletop notation. From a simple d20 to dice pools, exploding dice and mathematical expressions, it handles the rolls and gives you access to the results.

Built with tabletop role-playing games in mind, it can power character builders, virtual tabletops, game tools and other applications that need more than a basic random number.

How it works ​

Describe a roll using dice notation: a string that specifies the dice to roll, any modifiers to apply, and how to calculate the total.

For example:

  • d20 — roll one twenty-sided die.
  • 2d6+3 — roll two six-sided dice and add three.
  • 4d6kh3 — roll four six-sided dice and keep the highest three.
  • d6! — roll a six-sided die, rolling again whenever it lands on six and adding the extra rolls.

The library interprets the notation, rolls the dice and applies the modifiers. You can inspect the individual results, use the calculated total, or format the roll for display.

Start with Getting started to install the library, or explore the notation guide to see what you can roll.

You can also try the dice playground to experiment with notation and roll dice in your browser, without installing the library or writing any code.

Features ​

Dice types ​

Roll the dice your game needs:

Roll modifiers ​

Apply modifiers individually or combine them to build more complex rolls:

Groups and calculations ​

Build expressions that bring several rolls together:

Results and roll history ​

Work with the results beyond their final totals:

Customisation ​

Adapt the library to your game or application:

See the API reference for the available extension points.

Random number generation ​

By default, rolls use JavaScript’s Math.random() through the library’s random engine.

You can supply a different engine when you need another source of randomness, or use a seeded engine to reproduce the same sequence of rolls. This can be useful for testing, debugging and repeatable game scenarios.

Environment support ​

The library supports modern browsers and includes TypeScript type definitions. ES module and UMD builds are available for different environments.

We actively support the latest Node.js LTS release. Older versions may work, but aren’t officially supported or tested.

Supported Node.js version

See Getting started for installation and import options.

Other projects in the Dice Roller ecosystem include:

  • Online tools for experimenting with dice notation in an interactive playground and converting saved roll data.
  • Vue components for adding dice rolling to Vue applications.
  • The VitePress plugin used for interactive rolls in this documentation. New in v6
  • A command-line interface for rolling dice in your terminal.
  • A data converter for converting saved roll data between export schema versions. New in v6

MIT Licensed · Credits