Create a randomly generated melody based on the chord-progression playing?

Are there any good tutorials, guides or examples that shows how to create a melody based on the current chord playing, with consideration to stuff like pauses and harmony, so that the melody doesn’t sound completely random? I know I sound pretty shallow in my request, but I am very new to programming and only have a simple knowledge of basic music theory.


this comes up quite often in variants, so I’m repeating my answer from here:

see the data sharing chapter of the Practical Guide

here a more recent example from the list

and three threads on the forum with related examples

There are countless other examples in the old archive if you search “data sharing”

In any case note the time-shift, which is necessary in most examples for order of execution.