Roll dice using a random number generator. Use when asked to roll a die (d4, d6, d8, d10, d12, d20, d100), roll multiple dice, or generate random dice rolls for tabletop RPGs, board games, or decision making.
Use this skill when the user needs to:
Generate a random number from 1 to the given number of sides:
# Bash (macOS/Linux)
echo $((RANDOM % <sides> + 1))
# PowerShell (Windows)
Get-Random -Minimum 1 -Maximum (<sides> + 1)
# Python (more precise for large numbers)
import random
print(random.randint(1, <sides>))
Replace <sides> with the number of sides on the die (e.g., 6 for a standard die, 20 for a d20).
| Notation | Sides | Common Use |
|---|---|---|
| d4 | 4 | Small damage rolls |
| d6 | 6 | Standard die, ability scores |
| d8 | 8 | Weapon damage |
| d10 | 10 | Percentile rolls (paired) |
| d12 | 12 | Greataxe damage |
| d20 | 20 | Attack rolls, skill checks, saving throws |
| d100 | 100 | Percentile rolls |
For NdX notation (N dice with X sides):
# Roll 3d6 (three six-sided dice)
for i in {1..3}; do echo $((RANDOM % 6 + 1)); done | paste -sd+ | bc
import random
def roll(n, sides, modifier=0):
rolls = [random.randint(1, sides) for _ in range(n)]
total = sum(rolls) + modifier
return {"rolls": rolls, "modifier": modifier, "total": total}
# Examples
print(roll(3, 6)) # 3d6
print(roll(1, 20, 5)) # 1d20+5
print(roll(2, 8, -1)) # 2d8-1
When the user provides dice notation like "2d6+3", parse it:
import re
import random
def parse_and_roll(notation: str) -> dict:
match = re.match(r"(\d+)?d(\d+)([+-]\d+)?", notation.strip().lower())
if not match:
return {"error": f"Invalid notation: {notation}. Use format: NdX+M (e.g., 2d6+3)"}
n = int(match.group(1) or 1)
sides = int(match.group(2))
modifier = int(match.group(3) or 0)
rolls = [random.randint(1, sides) for _ in range(n)]
total = sum(rolls) + modifier
result = f"{notation} → {rolls}"
if modifier:
result += f" {'+' if modifier > 0 else ''}{modifier}"
result += f" = {total}"
return {"notation": notation, "rolls": rolls, "modifier": modifier, "total": total, "display": result}
# Usage
print(parse_and_roll("2d6+3"))
print(parse_and_roll("d20"))
print(parse_and_roll("4d8-2"))
$RANDOM range: $RANDOM produces 0-32767. For dice this is fine, but for very large ranges use Python's random.randint().random.randint(1, N) is correct; random.randrange(1, N) excludes N.After rolling: