Appendix: Hexagram Divination Code
Backend code that simulates the manual yarrow stalk divination process
divideStalks(stalks)
: Simulates dividing the stalks into two random piles.countByFours(pile)
: Simulates counting out stalks in groups of four and returning the remainder.yarrowStalkLine()
: Performs the entire process for generating one line:Does the first division, setting aside one stalk.
Performs the second and third divisions.
Calculates the total and returns the appropriate line value.
castHexagram()
: CallsyarrowStalkLine()
six times to generate a complete hexagram.
This implementation closely replicates the traditional yarrow stalk method, including:
Starting with 49 stalks
Performing three divisions for each line
Calculating the results based on the sums of these divisions
The probabilities generated by this method will match those of the traditional yarrow stalk method:
6 (Old Yin): 1/16 chance
7 (Young Yang): 5/16 chance
8 (Young Yin): 7/16 chance
9 (Old Yang): 3/16 chance
Last updated