Skip to content
RANDSUM

The TypeScript dice engine

Throw Dice,
Not Exceptions.

Parse and roll any dice notation, from 1d20+5 to exploding, rerolling, drop-lowest pools, and get every step back as typed data. Zero dependencies, with ready-made rules for D&D 5e, Blades in the Dark and more.

Try @randsum/roller

Runs in your browser

Roll your own way

One engine, many ways in: a library, ready-made games, React components, a public API, a roller app for your phone, a Discord bot, an agent plugin and an open spec.

roller

A typed dice roll in three lines

roll() takes a number, a notation string or an options object, and returns the total with every die and every modifier step that produced it.

index.ts
import { roll } from '@randsum/roller'
const { total, rolls } = roll('4d6L')
console.log(total)
// 15
console.log(rolls[0].initialRolls)
// [1, 5, 4, 6]
console.log(rolls[0].rolls)
// [4, 5, 6]
console.log(rolls[0].description)
// ["Roll 4 6-sided dice", "Drop lowest"]
  • Every modifier, parsed

    Drop, keep, reroll, explode, cap, unique and count successes, plus Fate, percentile, wild, geometric and draw dice.

  • Errors before dice

    Bad notation throws a typed error before anything is rolled, so you catch it where you wrote it.

  • Runs everywhere

    Plain ES modules with full type declarations, and no runtime dependencies. Bun, Node.js, Deno or the browser.

games

Describe a game, get a typed roller

Write a game's dice rules as a .randsum.json spec and @randsum/games generates a fully typed roller for that system. Adding a game is writing a config file.

salvageunion.randsum.jsonSalvage Union docs
{
"name": "Salvage Union",
"shortcode": "salvageunion",
"roll": {
"inputs": {
"tableName": { "type": "string" }
},
"dice": { "pool": { "sides": 20 }, "quantity": 1 },
"resolve": {
"remoteTableLookup": {
"url": "https://salvageunion.io/schema/roll-tables.json",
"find": {
"field": "name",
"input": "tableName",
"errorMessage": "Invalid table: \"${value}\""
},
"tableField": "table",
"resultMapping": {
"key": { "$lookupResult": "key" },
"label": { "$lookupResult": "result.label" },
"description": { "$lookupResult": "result.value" },
"tableName": { "$input": "tableName" }
}
}
}
}
}

Ready for your table

Each game resolves a roll by its own rules: hits and misses, hope and fear, the Fate ladder. Import one subpath and roll.

ui

Put the roller in your app

The roller on this page is a Web Component: one element in Max, Compact and Mini sizes, for any page or framework. @randsum/ui ships it, every part it is built from, React and Vue wrappers, Svelte types and React Native components, each as an import of its own.

index.html
<script type="module">
import '@randsum/ui/roller'
</script>
<randsum-roller size="mini" notation="4d6L"></randsum-roller>

Questions

What RANDSUM is, where it runs and what it costs. Anything else is in the docs.

What is RANDSUM?

RANDSUM is an open-source dice engine for TypeScript and JavaScript. Its core package, @randsum/roller, parses dice notation such as 4d6L or 2d20H, rolls it, and returns the total with every step that produced it. Around it sit ready-made game rules, drop-in roller components, a public HTTP API, an installable Roller app, a Discord bot, a plugin for AI agents and an open notation spec. Read the introduction

Which dice notation does it support?

Everything in RANDSUM Dice Notation: basic NdS rolls and arithmetic, plus modifiers for drop and keep, reroll, exploding, compounding and penetrating dice, caps, unique results, and counting successes or failures. Fate, percentile, wild, geometric and draw dice are built in. See the notation reference

Which games have ready-made rules?

@randsum/games covers D&D 5th Edition, Blades in the Dark, Daggerheart, Fate Core, Powered by the Apocalypse, Root: The Roleplaying Game and Salvage Union. Each game's rules are a .randsum.json spec, so you can write one for your own game. Browse the games

Where does it run?

@randsum/roller has no runtime dependencies and ships as ES modules with type declarations, so it runs in Bun, Node.js, Deno and the browser. CommonJS projects can use it through a bundler. Install it

Can I roll dice without writing code?

Yes. Install the Roller app on your phone, add the Discord bot to your server for game night, call the public API at api.randsum.dev with no key, or install the plugin so Claude and other agents roll real dice instead of guessing. See the agent tools

Is RANDSUM free?

Yes. Every package is MIT licensed and developed in the open on GitHub, and the API and Discord bot are free to use. View it on GitHub

Roll your first die in a minute.

Install the roller, or skip the install and call the API from anywhere. Free and MIT licensed.