TLDR; if you message the user kong_ming on this instance with a question, it will return a judgement from the Book of Changes, an ancient text used in divination.

I like to build hardware random number generators. I had an old prototype lying around that used diode avalanche noise. I’ve since made it smaller and cheaper, but it was perfectly functional, so I wanted to use it for something.

At it’s core, it consists of a BJT transistor that I pass current the wrong way through, at a moderate voltage (~16v). A big resistor keeps that current small, but it still happens in spikes whee the time between them has a high entropy.

After that, another transistor amplifies the signal, I use a DC blocking capacitor, and then amplify the signal some more using some old CD4069 hex inverters. This gets me a nice square wave of wildly varying period.

Next, an MCU has a little routine written in assembly that samples that signal, and measures two time intervals per 3 rising edges of my entropy source. If the intervals are measured as equal, it restarts the process. If the first interval is longer, it records a 1. If the second interval is longer, it records a zero.

When 8 recordings are done, it outputs the result out one of the MCU ports, and additionally toggles a pin to indicate that a new random 8-bit value is ready.

Next, I had to get that data to the internet. I used an ESP32, with the Adafruit MQTT library. A C++ program accumulates 224 bytes of entropy, and pushes that to an MQTT server. By coincidence, 3 of the I/O pins of the ESP32 were connected to an RGB LED on the development board, so it flashes pretty wild colors:

Next, I converted the entire text of the I Ching to JSON. The I Ching is divided into 64 hexagrams, each with an associated passage of text. Then, there is additional text depending on the “changing line” of your hexagram.

Long ago, these were once created by casting yarrow sticks. This created an unusual and unbalanced probability table for the different outcomes. In more modern (but still ancient) times, coin flips were used to determine the hexagram and changing lines – but this uses a ‘balanced’ probability table whee the 4 outcomes (yin, yang, changing yin, changing yang) have equal probabilities.

I decided to go with the ancient method, the yarrow-stick probabilities. This uses up more entropy (4 bits per hexagram line instead of 3) than the coin-flip method, as the probability table is more complex.

Then, I had to determine which changing line is considered. The rules for this are a bit annoying (https://en.wikibooks.org/wiki/I_Ching/The_Moving_Line). Presumably, the ancients did not consider algorithmic elegance an important part of divination. Long story short, regardless of how many changing lines are created, only zero, one, or in rare cases 6 of them can be considered.

Finally, I build a lemmy bot in Python that checks for new messages to kong_ming (named after a famous Daoist strategist). It discards messages of length zero, as an I Ching consultation requires that you reflect upon the question at hand. So you should write something about the matter at hand, keeping in mind the messages are not secure – so be as vague as you want. It will reply to each, as entropy permits. Usually you should get a response within a couple of minutes.

There we have it – ancient wisdom from the I Ching, a hardware random number generator on my desk in Vietnam, assembly language, C++, MQTT, Python, The Fediverse, and finally your eyeballs. Quite a convoluted tech stack!

REF: Yi Ching, translated by James Legge (1815 –1897)