← Guides

Seeding tarot draws: what the seed controls, and what it does not

A tarot draw should feel random to the person asking and be exactly repeatable for the developer who has to debug it. The optional seed gives you both, provided you know what it feeds into. This is the mechanism, step by step, with the consequences that surprise people.

Updated

From seed to cards

json
{ "spread": "three_card", "seed": "qa-fixture-001" }
  • The seed string is encoded as UTF-8 and hashed with SHA-256. The 32-byte digest becomes the four 64-bit words of a xoshiro256** generator.
  • That generator drives a Fisher-Yates shuffle of the whole 78-card Rider-Waite-Smith deck.
  • The spread takes the first N cards of the shuffled deck, in order: single 1, three_card 3, nine_card 9, celtic_cross 10.
  • Each card's orientation comes from a second generator seeded with the seed, the text ::orientation:: and the card's id, and is upright when its first number falls below one half, reversed otherwise. Across 3,000 seeded three-card draws, 50.1% of cards came out reversed.

With seed: "qa-fixture-001", POST /v1/tarot/draw returns The Devil, The Magician and the Knight of Wands, all upright - every time, on every server.

Consequences worth knowing

  • Spreads are prefixes of each other. Because every spread is a slice of the same shuffled deck, the same seed gives a Celtic Cross whose first three cards are the three-card spread, and a single card that is its first card. With qa-fixture-001, the Celtic Cross continues Four of Cups, Five of Cups, Eight of Cups (reversed), Queen of Swords, Six of Wands (reversed), Six of Cups (reversed), Five of Wands. If two features of your product must not show the same cards, give them different seeds.
  • Orientation follows the card, not the position. A card drawn with a given seed is upright or reversed whichever slot it lands in.
  • The seed is exact text. Adding one trailing space to user-1042:2026-12-05 gave a completely different three cards. Unicode seeds work (they are hashed as UTF-8). Trim and normalise any seed you build from user input.
  • The seed must be a string. "seed": 42 is a 400 VALIDATION_ERROR (expected string, received number); so are an empty string and anything over 120 characters. String(id) first.
  • The shuffle is fair in aggregate. Over 3,000 seeds, every one of the 78 cards turned up as the first card, between 27 and 53 times against an expected 38.5.

Without a seed

Leave seed out and the API generates one from 16 bytes of crypto.getRandomValues - the platform's cryptographic random source, not Math.random - and returns it as a 32-character hex seed in the response (for example 740b85cc86bf1f01647fd9196ac76038). Nothing about the draw is stored on our side, so if a reading may be reopened, shared or disputed, save that seed with it. Sending it back reproduces the draw exactly.

The mapping from seed to cards is part of the contract and is pinned by golden-value tests in the divination package. Each response also carries divination_version ("1.0.0" today); store it next to the seed so that a stored reading can be matched to the deck and meanings it was drawn under.

Seeds in tests

A fixed seed turns a random feature into an ordinary assertion. These tests pin a reading, check the prefix property, and check that an unseeded draw can be replayed from the seed it returns:

javascript
// tarot.test.mjs - run with: node --test tarot.test.mjs (Node 18+)
import { test } from "node:test";
import assert from "node:assert/strict";

const API = process.env.ASTRONODE_API ?? "https://api.astronode.dev";
const headers = { authorization: `Bearer ${process.env.ASTRONODE_API_KEY}`, "content-type": "application/json" };

const draw = async (body) => {
  const res = await fetch(`${API}/v1/tarot/draw`, { method: "POST", headers, body: JSON.stringify(body) });
  assert.equal(res.status, 200);
  return (await res.json()).data;
};
const ids = (d) => d.cards.map((c) => `${c.card.id}:${c.orientation}`);

test("a fixed seed is a fixed reading", async () => {
  const d = await draw({ spread: "three_card", seed: "qa-fixture-001" });
  assert.deepEqual(ids(d), ["major.devil:upright", "major.magician:upright", "wands.knight:upright"]);
});

test("a longer spread extends a shorter one", async () => {
  const three = await draw({ spread: "three_card", seed: "qa-fixture-001" });
  const celtic = await draw({ spread: "celtic_cross", seed: "qa-fixture-001" });
  assert.deepEqual(ids(celtic).slice(0, 3), ids(three));
});

test("no seed: the API picks one and returns it", async () => {
  const first = await draw({ spread: "three_card" });
  assert.match(first.seed, /^[0-9a-f]{32}$/);
  const replay = await draw({ spread: "three_card", seed: first.seed });
  assert.deepEqual(ids(replay), ids(first));
});
text
$ node --test tarot.test.mjs
✔ a fixed seed is a fixed reading
✔ a longer spread extends a shorter one
✔ no seed: the API picks one and returns it
ℹ tests 3
ℹ pass 3
ℹ fail 0

Yes/no and interpret

POST /v1/tarot/yes-no takes a question (3-500 characters) and the same optional seed, and uses the same shuffle: its card is the first card of a draw with that seed. A Major Arcana card answers yes upright and no reversed; a Minor Arcana card does the same now that every card's meaning is marked reviewed, and uncertain is kept for cards whose text is not. Of 600 seeded calls, 305 said yes and 295 no.

The question is not part of the seed. With seed: "qa-fixture-001", "Is this a good week to launch?" and "Should I sign the lease?" both drew The Devil upright and both got yes. If you derive one seed per user per day, every question that day gets the same answer - put the question into the seed if that is not what you want.

POST /v1/tarot/interpret is different in kind. It runs on the chat host, takes the cards you already drew (position, name, orientation, up to 8 keywords each, at most 10 cards) with a spread_label and optional question, and returns a written reading from a language model. It has no seed field and its text is not reproducible, so store the text itself. It was not called for this page; the tarot reading recipe walks through the mapping from a draw. /v1/tarot/draw and /v1/tarot/yes-no are on the Free plan.

Questions

How does the tarot seed produce the same cards?
The seed string is hashed with SHA-256 into a xoshiro256** generator that drives a Fisher-Yates shuffle of all 78 cards; the spread takes the first cards in order. Orientation comes from a separate generator keyed on the seed and the card. The same seed always gives the same draw.
Where does the randomness come from when no seed is sent?
The API generates a seed from 16 bytes of crypto.getRandomValues and returns it in the response as a 32-character hex string. Sending that seed back reproduces the draw.
Does the yes/no question change the card that is drawn?
No. The question is not part of the seed, so the same seed gives the same card and the same answer for any question. Include the question in the seed if different questions should draw different cards.