Show HN: I Ching simulator with accurate Yarrow Stalk probabilities (castiching.com)

63 points by jackzhuo ↗ HN
I built this because I wanted a digital I Ching that honors the original math, rather than just Math.random().

Technical detail for the curious:

The simulation follows the traditional Yarrow Stalk algorithm (Da Yan). The core of this algorithm relies on modulo-4 arithmetic on the stalks remaining after a random split.

To make it physically realistic, I used a Box-Muller transform to simulate the user splitting the stalks with a Gaussian distribution (since humans naturally tend to split near the middle), rather than a uniform random split.

I was worried this 'human bias' might skew the modulo probabilities, so I ran a 1-million-run Monte Carlo simulation to verify.

The Result: The remainders [0,1,2,3] still emerged with a near-perfect 25% distribution (deviation < 0.05%).

So, the app simulates the physics of human imperfection while preserving the mathematical perfection of the probability distribution (where Old Yin is 1/16).

Stack: Next.js + Tailwind css

Happy to answer any questions about the math or the hexagrams!

29 comments

[ 4.1 ms ] story [ 49.7 ms ] thread
(comment deleted)
I can’t get this to work on iOS at all - question - coin or yarrow choice - then what? No links seem to be hot/working. A little tutorial would be great. Fun project!
Some kind of text on what the resulting hexagrams mean along with their names would be nice for those of us who haven't memorized the meaning of all sixty-four.
You are right—there is no detailed text yet.

To be honest, I haven't added it because I'm hesitating. I planned to use AI to generate the interpretations, but I'm not sure if that's a good idea.

I feel like letting AI explain the I Ching might kill the 'traditional vibe'.

I'm still deciding: should I use AI, or just use the classic book text? What do you think?

Please consider improving the color contrast. The text is gray-on-gray and impossible to read.
Thanks for pointing this out!

I probably stared at it for too long on my own monitor and got used to it. I will bump up the contrast in the next update to ensure it's readable for everyone.

Any sites that give nice barebones explanation of the results? I imagine filling more of the blanks myself instead of AI is part of the exercise, but a nice starting point can help.
I'm curious, and I figure you would know more about this than I do: when using real yarrow stalks for the I Ching, how do you split them into groups? I mean like, roughly equal? Don't think about it too much and just split? Just separating them into, say, groups where one group is just a single stalk doesn't seem random.

I guess it's a question of philosophy, either split into groups based off of your intuition, or aim for a truly random split in the pile.

Anyway, I wasn't sure if this is something that's a settled matter or what.

OP here. This discussion is exactly why I implemented the Box-Muller transform!

You are right that humans don't split perfectly randomly (Uniform Distribution). We tend to aim for the middle but miss slightly.

In my code, I modeled this 'human splitting action' using a Gaussian (Normal) distribution centered at 50% of the pile, with a standard deviation. This simulates the user trying to split the stalks roughly in half, rather than just picking a random number from 0 to 49.

Interestingly, my Monte Carlo simulations showed that even with this human bias (splitting near the middle), the final modulo-4 probabilities remain stable. So the algorithm is robust even against our 'imperfect' hands.

As a fellow iChing developer - this is nice! Thanks for sharing.
Thank you! Always happy to meet a fellow developer in this niche.

Have you built a web app or a mobile app? I'd love to check out your work if you have a link!

Any chance to make Enter or Spacebar press the button when Yarrow Stalk thing progresses?

It got tiring and boring to click and click and click with the mouse with no explanation for how it works

> "What should I use for 15V 150mA DC power supply?"

Original Hexagram 45. GATHERING TOGETHER (MASSING) (Ts'ui)

Transformed Hexagram 17. FOLLOWING (Sui)

Ok.

Asking the Oracle for circuit design specs... I love it!

My interpretation for your power supply:

Gathering (45): You need to gather some capacitors? (or maybe a heat sink for the 'massing'?)

Following (17): Clearly it's telling you to use a Voltage Follower. :D

(comment deleted)
Fun fact: archaeological evidence on I Ching divinatory records shows an hexagram distribution different from the one produced by the yarrow stalk method. Meaning that, while it is now considered the traditional method, it was likely not the original approach.
Naive question: could this have been survivorship bias? Could certain ones not have been written down or kept with the others?
That's a really cool fact about the archaeology!

To be honest, my reason for picking this method was simple: I was reading a book about the I Ching that described the different ways to cast hexagrams.

The Yarrow Stalk method stood out to me because it felt more mysterious—in the past, it seemed like a secret method known only by a few experts.

Also, from a coding perspective, this algorithm was just much more interesting to build than a simple coin toss!

The I Ching contains all 6-bit patterns.
The hexagrams can be modeled with only 6-bits, but this does not contains enough information for a proper reading of I Ching which also need to account for line changes. So there are really 4 lines: young yin, old yin, young yang, old yang.

A fundamental part of I Ching reading is the implication that each present state is in the process of transforming to another.

Now i feel like i need to read The Man in the High Castle again.
i wonder if a query to thise quantum random bumber generator machines would help
I got a result using coins but could find no link to the hexagram so had to look it up on another site. While I was clicking around your site trying to find the hexagram then I lost my reading and back button didn't work, so changing lines etc were lost. I would love to use this more but not in current state.
OP here with a massive update!

I spent the last 24 hours implementing the feedback from this thread. Thank you all for the harsh (but fair) critique.

1. Ditched AI for the Classics Many of you pointed out that AI interpretations felt "soulless" or risky. I agreed.

Now: The app directly displays the canonical Richard Wilhelm / Cary Baynes translation (Foreword by Carl Jung) for the Primary Hexagram, Moving Lines, and the Relating Hexagram. It's mathematically precise and respects the source material.

2. No More Lost Readings (Persistence) @jmkd mentioned losing a reading on refresh.

Fix: The latest reading is now auto-saved to Local Storage.

Privacy: Still no login required. Your data stays in your browser.

3. Shareable "Result Cards" Since the hexagrams look so cool, I added a feature to generate a downloadable image card. It captures the visual pattern and the key judgment text.

Give it another spin and let me know if the "Moving Lines" logic feels right to you now!

My Reading, Yarrow Stalks results:

_____ (black bar, 7)

_____ (black bar, 7)

__.__ (grey bar, marked by green dot in the middle, 9)

__ __ (two short black bars with gap in the middle, 8)

__.__ (grey bar, marked by green dot in the middle, 9)

__ __ (two short black bars with gap in the middle, 8)

Primary Hexagram 6. CONFLICT (Sung)

Relating Hexagram 20. CONTEMPLATION (Kuan)

Reverse engineer the question :->