The Math of Casting
A spec for the curious — how we turn "drawing numbers" from a three-thousand-year-old practice into a procedure you can read, run, and verify in any language.
Every hexagram is
the same data structure.
Whether the input is three coins, yarrow stalks, or a string of bytes, every result reduces to the same internal form: an array of length 6, each entry ∈ {6, 7, 8, 9}.
- 7 / 8 are static lines
- 6 / 9 are moving lines — they flip into their opposite
→ 6 lines bottom-to-top determine the primary hexagram (64 options)
→ moving positions determine the resulting hexagram
So a cast is not "a number" — it is primary → resulting, two states with a transformation. Each method just defines how to pick the six values.
Three Coins · Binomial
The simplest method. Three coins, each tails = 2 and heads = 3. The sum is exactly one of {6, 7, 8, 9}. Lines are independent; throw six times.
Procedure
sum of 3 coins ∈ { 6, 7, 8, 9 }
→ P(6) = 1/8, P(7) = 3/8, P(8) = 3/8, P(9) = 1/8
Distribution
Yarrow Stalk · The Asymmetric Truth
The classical method from the "Great Treatise." Fifty stalks, one set aside. Three "variations" produce one line; eighteen variations produce a hexagram. Its importance is not the ritual but its probability distribution, which is different from the three-coin method.
Procedure
three variations make one line · eighteen make a hexagram
→ P(6)=1/16, P(7)=5/16, P(8)=7/16, P(9)=3/16
Distribution
Plum Blossom · Modular Arithmetic
Shao Yong's invention: rewrite "drawing numbers" as deterministic arithmetic. Any integer enters; time is just integers.
From Time
lower = (upper_sum + hour) mod 8
moving = (year_branch + month + day + hour) mod 6
From Numbers
lower = B mod 8
moving = (A + B) mod 6
From Anything · The Modern Pipeline
Open the input surface — anything that can be turned into bytes can be cast.
INPUT
text / audio / image / any bytes
NORMALIZE
UTF-8 / PCM / greyscale pixels
HASH
SHA-256(bytes) → 32 bytes
MODULUS
h[0..5] mod 2 → six lines
h[6] mod 6 → moving line
LOOKUP
6-bit binary → 64-hexagram table
Design principle · the same input always yields the same hexagram. Unlike coins or yarrow stalks, this is a deterministic mapping — anyone can reproduce a cast in any language.
Where does randomness come from?
Traditional · Cryptographic
All random operations (coin toss, yarrow division) call the OS CSPRNG — Ruby SecureRandom / Linux /dev/urandom.
Modern · Fully Deterministic
Modern methods introduce no randomness. Same bytes = same hexagram. Think of it as a fingerprint of your input.
"Can it predict things?"
Yes — in the mathematical sense. It accurately predicts that "two identical inputs will yield the same hexagram" and "you'll get a young-yin on roughly 7/16 of all casts using yarrow."
It cannot predict whether you'll get a raise next year, because there is no causal link between a probability distribution and your paycheck — the "correspondence" between the two is cultural, not physical. Anygua does the math part as well as it can be done. The cultural part is yours.
That's why casting is always free and unlimited. This is a tool, not a product.