Skip to main content

Dice Roll API

MOCK DATA

Roll dice in standard NdS+M notation (2d6+3, d20, 4d8-2) — get each die result, the modifier and the total, with seedable, reproducible rolls.

Generated test data for fixtures and development

Base URL
/api/dice
Capabilities
1 route Seedable
Last updated
July 29, 2026

GET /api/dice/roll

Each record is one independent roll of the whole notation; count rolls it several times. 2d6+3, 2d6%2B3 and 2d6 3 are all the same roll (a raw + decodes to a space).

Live requestRuns against the public API
No key required
GET/api/dice/roll?notation=2d6%2B3

Request parameters

Dice notation NdS+M (case-insensitive): N dice (1-100, default 1) with S sides (2-1000) and an optional modifier M (-1000..+1000), e.g. 2d6+3, d20, 4d8-2. A raw '+' decodes to a space in query strings, so '2d6+3', '2d6%2B3' and '2d6 3' are all read as 2d6+3.

Advanced response options7 options

How many records to generate (1–100).

Deterministic output: the same seed always returns the same records. Omit for random (the used seed is echoed in meta.seed).

Return only these fields (comma-separated). Mutually exclusive with 'exclude'.

Return all fields except these (comma-separated).

Response format: json envelope, ndjson (one record per line) or csv.

Pretty-print the JSON response.

Drop the envelope: return the raw array/object without data/meta wrapper.

Response

Example parameters are ready. Send the request to inspect the live response.

Route reference

Code samples Ready-to-copy requests in 4 languages
Choose a code sample language
curl "https://randomapi.dev/api/dice/roll?notation=2d6%2B3"
const res = await fetch("https://randomapi.dev/api/dice/roll?notation=2d6%2B3");
const { data, meta } = await res.json();
import requests

data = requests.get("https://randomapi.dev/api/dice/roll?notation=2d6%2B3").json()["data"]
$json = json_decode(file_get_contents(
  "https://randomapi.dev/api/dice/roll?notation=2d6%2B3"
), true);
$data = $json["data"];
Parameters Route-specific request inputs 1
notation string

Dice notation NdS+M (case-insensitive): N dice (1-100, default 1) with S sides (2-1000) and an optional modifier M (-1000..+1000), e.g. 2d6+3, d20, 4d8-2. A raw '+' decodes to a space in query strings, so '2d6+3', '2d6%2B3' and '2d6 3' are all read as 2d6+3.

default: 1d6
example: notation=2d6+3
Universal parameters Shared response and formatting options 7
count int

How many records to generate (1–100).

default: 1
allowed: 1 – 100
example: count=3
seed int

Deterministic output: the same seed always returns the same records. Omit for random (the used seed is echoed in meta.seed).

example: seed=42
fields list

Return only these fields (comma-separated). Mutually exclusive with 'exclude'.

example: fields=index,notation
exclude list

Return all fields except these (comma-separated).

example: exclude=total
format enum

Response format: json envelope, ndjson (one record per line) or csv.

default: json
allowed: json | ndjson | csv
example: format=csv
pretty boolean

Pretty-print the JSON response.

default: false
example: pretty=true
unwrap boolean

Drop the envelope: return the raw array/object without data/meta wrapper.

default: false
example: unwrap=true
Response schema Fields returned in each record 5
index integer

Zero-based position of this independent roll in the returned batch.

example: 0

notation string

Canonical lowercase echo of the roll: explicit dice count ('d20' → '1d20'), zero modifier omitted.

example: 2d6+3

dice integer[]

Each individual die result in roll order — exactly N values, every one between 1 and S.

example: [4,2]

modifier integer

The flat modifier from the notation (0 when it has none).

example: 3

total integer

Sum of all dice plus the modifier.

example: 9

Documented examples

Build-generated requests and complete responses
4
One 2d6+3 roll
GET /api/dice/roll?notation=2d6%2B3
{
  "data": [
    {
      "index": 0,
      "notation": "2d6+3",
      "dice": [
        3,
        5
      ],
      "modifier": 3,
      "total": 11
    }
  ],
  "meta": {
    "endpoint": "dice",
    "route": "/roll",
    "count": 1,
    "seed": 42,
    "params": {
      "notation": "2d6+3"
    },
    "generatedAt": "2026-07-29T08:13:22.000Z"
  }
}
A raw '+' works too (decodes as a space)
GET /api/dice/roll?notation=2d6+3
{
  "data": [
    {
      "index": 0,
      "notation": "2d6+3",
      "dice": [
        3,
        5
      ],
      "modifier": 3,
      "total": 11
    }
  ],
  "meta": {
    "endpoint": "dice",
    "route": "/roll",
    "count": 1,
    "seed": 42,
    "params": {
      "notation": "2d6+3"
    },
    "generatedAt": "2026-07-29T08:13:22.000Z"
  }
}
Five d20 rolls
GET /api/dice/roll?notation=d20&count=5
{
  "data": [
    {
      "index": 0,
      "notation": "1d20",
      "dice": [
        10
      ],
      "modifier": 0,
      "total": 10
    },
    {
      "index": 1,
      "notation": "1d20",
      "dice": [
        1
      ],
      "modifier": 0,
      "total": 1
    },
    {
      "index": 2,
      "notation": "1d20",
      "dice": [
        18
      ],
      "modifier": 0,
      "total": 18
    },
    {
      "index": 3,
      "notation": "1d20",
      "dice": [
        4
      ],
      "modifier": 0,
      "total": 4
    },
    {
      "index": 4,
    …
    "generatedAt": "2026-07-29T08:13:22.000Z"
  }
}
Reproducible 4d8-2 batch
GET /api/dice/roll?notation=4d8-2&count=3&seed=42
{
  "data": [
    {
      "index": 0,
      "notation": "4d8-2",
      "dice": [
        4,
        6,
        5,
        3
      ],
      "modifier": -2,
      "total": 16
    },
    {
      "index": 1,
      "notation": "4d8-2",
      "dice": [
        1,
        1,
        4,
        5
      ],
      "modifier": -2,
      "total": 9
    },
    {
      "index": 2,
      "notation": "4d8-2",
      "dice": [
        7,
        1,
        3,
        4
      ],
      "modifier": -2,
      "total": 13
    }
  ],
  "meta": {
    …
    "generatedAt": "2026-07-29T08:13:22.000Z"
  }
}

About this API

Coverage & behavior

Rolls standard tabletop dice notation NdS+M: N dice with S sides each, plus an optional flat modifier M. N defaults to 1 (d20 = 1d20), the modifier may be + or -, and case doesn't matter (2D10-2 works). Limits: 1–100 dice, 2–1000 sides, modifier −1000…+1000 — anything else is a clear 400 that repeats the format (Use NdS+M, e.g. 2d6+3, d20, 4d8-2).

The + gotcha: in a raw URL query string a literal + decodes to a space, so this endpoint treats internal whitespace as the + you typed. notation=2d6+3 and notation=2d6%2B3 both work and mean the same roll — no silent "modifier lost" surprises.

Each record is one independent, indexed roll of the whole notation: ?notation=2d6%2B3&count=10 returns ten separate 2d6+3 rolls, each with its zero-based index, individual die results (dice), modifier, and total (sum of dice + modifier — verifiable per record). The index keeps repeated outcomes distinguishable; notation echoes the canonical lowercase form (D201d20), and a pinned seed makes every roll byte-identical forever.

Use it for

  • Power a Discord/Slack dice bot without writing your own notation parser
  • Roll D&D damage and ability checks server-side so clients can't tamper with results
  • Reproducible game-logic tests: seed + count=100 gives a fixed batch of rolls in every CI run

Frequently asked questions

What notation is supported?

Classic tabletop notation — NdS with an optional modifier, like 2d6+3 or 1d20-1. The response shows each individual die plus the modifier and total.

Are the rolls fair?

Each die is uniform over its sides via the seeded PRNG; pass seed to replay an exact session or omit it for fresh rolls per request.

Can I roll in bulk?

count repeats the same notation up to 100 times in one call — handy for statistics or bulk simulation.