AnvilJSON utilities

Anvil › Docs › /v1/random

Random number API: integers, dice rolls and coin flips

Three small random jobs in one endpoint: whole numbers in any range (with or without repeats), dice in standard tabletop notation, and coin flips. Everything comes from the operating system's cryptographic generator, so results are unbiased and unpredictable.

In one line: GET /v1/random?dice=3d6 returns JSON. No key, CORS on, 60 requests a minute.
GET

/v1/random

Random integers, coin flips or dice rolls. Change the values and press Send request to call the live API.

Parameters

NameTypeWhat it doesDefault
minintegerLowest value (integers mode)1
maxintegerHighest value100
countinteger1 to 1001
uniquebooleanNo repeatsfalse
dicestringDice notation like 2d6+1 (overrides min/max)—
coinbooleanFlip coins insteadfalse

Example

Request:

GET https://api.oddlathe.com/v1/random?dice=3d6

Response (generated by the real code when these docs were last built; random or time-based values will differ for you):

{
 "notation": "3d6",
 "rolls": [
  5,
  3,
  4
 ],
 "modifier": 0,
 "total": 12
}

Code examples

curl
curl 'https://api.oddlathe.com/v1/random?dice=3d6'
JavaScript (browser or Node 18+)
const params = new URLSearchParams({
  dice: "3d6"
});
const res = await fetch(`https://api.oddlathe.com/v1/random?${params}`);
if (!res.ok) throw new Error((await res.json()).error.message);
const data = await res.json();
console.log(data);
Python (standard library only)
import json, urllib.parse, urllib.request

params = urllib.parse.urlencode({"dice": "3d6"})
url = "https://api.oddlathe.com/v1/random?" + params
# Send a User-Agent: the edge network refuses Python's default one.
req = urllib.request.Request(url, headers={"User-Agent": "my-script/1.0"})
with urllib.request.urlopen(req, timeout=10) as r:
    data = json.load(r)
print(data)

When it's useful

  • Prize draws and picking a random winner from a numbered list (use unique=true)
  • Dice for tabletop games, Discord bots or teaching probability
  • Random sampling in spreadsheets or no-code tools

Good to know

  • Dice notation: NdS rolls N dice with S sides; add +K or -K for a modifier. Up to 100 dice with 2 to 1000 sides.
  • Unique draws need the range to hold at least count values, otherwise you get a bad_param error instead of a loop.
  • Ranges can go from −10¹² to 10¹². min and max are both included.

Uses a cryptographically secure generator, so results are unpredictable and unbiased.

Errors

Errors are JSON like {"error": {"code": "…", "message": "…"}}. The ones this endpoint can return:

  • bad_param (400): a value is the wrong type or out of range (the message says which)
  • rate_limited (429): over 60 requests a minute; wait for Retry-After seconds

Questions

Is it truly random?

It uses the operating system's cryptographically secure generator, the same source used for encryption keys. That's unpredictable for every practical purpose, including fair draws.

Can I prove a draw was fair afterwards?

Not from this API alone, because nothing is logged. For a publicly verifiable draw, publish the method and the time, run it live, and share the response.

Related endpoints

Published · OpenAPI 3.1 spec · Limits and privacy