I played with this idea when I was doing an algorithmic composition project. I started with a Markov chain analysis of a simple Chopin etude, which gave me parameters, such as: - The distance between the lowest and highest note is 2 octaves - The key won't change, so there are only 8 notes per octave and given the first parameter, I only had 17 notes to choose from. - The shortest note was an 1/8th and the longest was a half. Most were quarters and there were a few dotted quarters (if I recall) so there were 4 note lengths to choose from. - The main melody in the original was 4 measures (again, if I recall) so my generated melodies were set to be that length, and always end on the root
Given all of these parameters, there were still many thousands of combinations. Applying the Markov chain limited that a lot, but that was only to make it sound like Chopin (which it did, a little). However, most of the thousands of combinations sound like crap, which is not an insignificant point. If you're willing to call some random sequence of notes a melody, then there are an infinite number