I am learning music theory, so I did this to try and grasp the basic concepts. The resulting melodies aren't always so melodic, but at least the basics are there. Below is the creation process
step 1: figuring out the key the key is decided randomly between all 12 root notes, then randomly assigned major (black) or minor (graey). ---You will hear the key play before the next step--- step 2: chord progression a 4-chord progression is randomly assigned. The singular notes of these chords are assigned to the 4 measures. ---You will hear the chord progression play before the next step--- step 3: constructing the melody a melody is randomly built for each measure using notes from the chord. I couldn't figure out passing notes, however I did include inverted chords for the sake of staying in a singular octave. ---You will hear the melody as a loop from this point on--- If anyone can help me code more advanced music theory elements, feel free to remix and adapt this project with a more advanced note selection method.