Several things I am into to make stuff like that :
oriented graphs
Artificial neural networks
probability density functions (?)
rounding notes to a list of permitted notes (like in the old muzaq)
But it is a long trip... If you want to walk along... Frankenstein is
very similar to all this. I will get back into all of this in the next
severals weeks, I'd say.