Roll the dice

Missing dice? Generate a random dice roll between one and six. Use dice with more sides, and choose as many dice as you need. Perfect for board games.

Face with waiting expression Nothing to see yet!

Loading takeymakey...
TakeyMakey code
Want this tool to do something else? Edit the code below and make it do whatever you want.
({
  take: [
    { type: "number", min: 1, label: "Number of dice" },
    { type: "number", min: 1, label: "Number of sides" },
    { type: "button", action: "make", label: "Roll the dice" },
  ],
  make: ([diceCount, faceCount]) => {
    if (diceCount <= 0)
      return [{ type: "status", value: 0, message: "No dice!" }]

    const result = Array.from({ length: diceCount }, (n, i) => ({
      type: "number",
      value: 1 + Math.floor(Math.random() * (faceCount - 1)),
      label: "Dice " + (i + 1),
    }))

    if (result.length > 1) {
      result.unshift({
        type: "number",
        value: result.reduce((m, e) => m + e.value, 0),
        label: "Total for this dice roll",
      })
    }

    return new Promise((resolve) =>
      window.setTimeout(() => resolve(result), 300)
    )
  },
})