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:
- Standard dice, including familiar dice such as d6 and d20.
- Percentile dice.
- Fudge and Fate dice.
- Range dice, with custom minimum and maximum values, including negative numbers. New in v6
- Face dice, with individually defined face values. New in v6
- Custom dice definitions for your own game mechanics. New in v6
Roll modifiers ​
Apply modifiers individually or combine them to build more complex rolls:
- Exploding, compounding and penetrating dice.
- Matching-batch explode rolls another batch when every die in the batch has the same value. New in v6
- Keep or drop results.
- Re-roll dice or require unique results.
- Count successes and failures.
- Set minimum and maximum die results.
- Sort results.
Groups and calculations ​
Build expressions that bring several rolls together:
- Roll groups and apply modifiers to their results.
- Combine dice with mathematical operators and functions.
- Use parentheses to control the order of calculations.
Results and roll history ​
Work with the results beyond their final totals:
- Inspect individual dice and evaluated expressions.
- Keep a history of rolls.
- Export and import rolls.
- Format results for display using presenters.
Customisation ​
Adapt the library to your game or application:
- Customise the behaviour of built-in modifiers. New in v6
- Choose a different random number generator.
- Use seeded engines for repeatable rolls.
- Create presenters that format results as text, HTML or other output. New in v6
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.
See Getting started for installation and import options.
Related projects ​
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