Anygua EST · 2026
Anygua/The Math

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.

CHAPTER · 00

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}.

line ∈ { 6 old-yin, 7 young-yang, 8 young-yin, 9 old-yang }
- 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.

CHAPTER · 01

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.

Classic

Procedure

heads = 3, tails = 2
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

6 old-yin1/80.125
7 young-yang3/80.375
8 young-yin3/80.375
9 old-yang1/80.125
CHAPTER · 02

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.

Classic

Procedure

49 → divide → hang one → count by fours → gather remainder
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

6 old-yin1/160.0625
7 young-yang5/160.3125
8 young-yin7/160.4375
9 old-yang3/160.1875
CHAPTER · 03

Plum Blossom · Modular Arithmetic

Shao Yong's invention: rewrite "drawing numbers" as deterministic arithmetic. Any integer enters; time is just integers.

From Time

upper = (year_branch + month + day) mod 8
lower = (upper_sum + hour) mod 8
moving = (year_branch + month + day + hour) mod 6

From Numbers

upper = A mod 8
lower = B mod 8
moving = (A + B) mod 6
CHAPTER · 04

From Anything · The Modern Pipeline

Open the input surface — anything that can be turned into bytes can be cast.

01

INPUT

text / audio / image / any bytes

02

NORMALIZE

UTF-8 / PCM / greyscale pixels

03

HASH

SHA-256(bytes) → 32 bytes

04

MODULUS

h[0..5] mod 2 → six lines
h[6] mod 6 → moving line

05

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.

CHAPTER · 05

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.

CHAPTER · 06

"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.