Readit News logoReadit News
Posted by u/jackzhuo 2 months ago
Show HN: I Ching simulator with accurate Yarrow Stalk probabilitiescastiching.com/...
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!

nestorD · 2 months ago
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.
jackzhuo · 2 months ago
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!

z2 · 2 months ago
Naive question: could this have been survivorship bias? Could certain ones not have been written down or kept with the others?
nestorD · 2 months ago
I doubt it. The I Ching does not really have bad / low interest hexagrams. Also historians who studied the topic seem pretty sure that the yarrow stalk method is a recent introduction (by I Ching standards, we are talking about a bronze age divination tool...).
jackzhuo · 2 months ago
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!

egypturnash · 2 months ago
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.
jackzhuo · 2 months ago
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?

goopypoop · 2 months ago
why throw mud into the water?
ohbleek · 2 months ago
I believe that is what is listed at the bottom of the page.
helterskelter · 2 months ago
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.

jackzhuo · 2 months ago
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.

helterskelter · 2 months ago
Very cool, thanks for the response. Neat project btw.
ksymph · 2 months ago
Functionally it makes no difference whether you split near the middle or not -- a truly random selection would sometimes end up with a pile of one, and that's totally fine. As long as you're not trying to game the system by, say, specifically counting out the sticks to get the outcome you want, it makes no difference. (and if you're doing that, then what's the point?)

Splitting closer to the middle does make it easier to avoid unintentionally counting though. If you make the same splits every time, you'll get the same outcome of course.

Philosophically / spiritually speaking, "don't think about it too much and just split wherever feels right" is the simple answer. Keep in mind the question you want to ask when you make the split and let whatever happens happen. Close your eyes if it helps you focus.

helterskelter · 2 months ago
> Functionally it makes no difference whether you split near the middle or not -- a truly random selection would sometimes end up with a pile of one, and that's totally fine.

Yeah I just mean I would be very conscious of splitting with a single stalk in one group and would wonder if that was really a 'fair' selection or something I did intentionally since I know the exact number of the yarrow in one hand. In practice, I can't imagine anyone would make a selection like that, even though in a truly random system it would happen not infrequently.

Jimpulse · 2 months ago
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.
thefaux · 2 months ago
The canonical western text is Richard Wilhelm's german interpretation, translated to english by Cary Baynes. This site has the hexagram descriptions from that translation: https://www.iching.online/wilhelm.php

I recommend buying the book though. It is fascinating whether or not you buy into it.

mistrial9 · 2 months ago
Carl Jung's Synchronicity text, published at the end of his life, uses I Ching as one testing ground..
Jimpulse · 2 months ago
Dang a Jung forward. Will have to pick it up! Thanks.
NooneAtAll3 · 2 months ago
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

jackzhuo · 2 months ago
OK, I will fix it.
blastro · 2 months ago
As a fellow iChing developer - this is nice! Thanks for sharing.
jackzhuo · 2 months ago
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!

v0id_p · 2 months ago
Hey Jack, I built an I Ching tool earlier this year using arrow.js. I tried to stick with vanilla JS at first but it proved difficult to maintain. My tool uses a casting method that results in the same probabilities as when one uses the Yarrow Stalk method, but doesn't include a yarrow stalk simulation. I briefly considered creating a 3D simulation of the yarrow stalk casting method but never got around to it. I find it interesting that someone had a similar idea.

My I Ching tool is located at classicofchanges.com

langitbiru · 2 months ago
Hello there. I'm also an I-Ching developer.

https://neoching.com

dvh · 2 months ago
> "What should I use for 15V 150mA DC power supply?"

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

Transformed Hexagram 17. FOLLOWING (Sui)

Ok.

jackzhuo · 2 months ago
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

dvh · 2 months ago
>Transformed Hexagram

toroid transformer?

Deleted Comment