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.
/v1/random?dice=3d6 returns JSON. No key, CORS on, 60 requests a minute./v1/random
Random integers, coin flips or dice rolls. Change the values and press Send request to call the live API.
Parameters
| Name | Type | What it does | Default |
|---|---|---|---|
min | integer | Lowest value (integers mode) | 1 |
max | integer | Highest value | 100 |
count | integer | 1 to 100 | 1 |
unique | boolean | No repeats | false |
dice | string | Dice notation like 2d6+1 (overrides min/max) | — |
coin | boolean | Flip coins instead | false |
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 'https://api.oddlathe.com/v1/random?dice=3d6'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);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:
NdSrolls N dice with S sides; add+Kor-Kfor a modifier. Up to 100 dice with 2 to 1000 sides. - Unique draws need the range to hold at least
countvalues, otherwise you get abad_paramerror instead of a loop. - Ranges can go from −10¹² to 10¹².
minandmaxare 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
/v1/passwordStrong random passwords with entropy estimate/v1/uuidRandom UUIDs (v4) or time-ordered UUIDs (v7)
Published · OpenAPI 3.1 spec · Limits and privacy