Nearly any reasonable metric of the goodness of melodic flow rates as the most melodic and flowing, the very epitomy of melody, a simple sustained note. To state the obvious, such a sustained note quickly becomes tiresome. Any system for melodic composition therefore needs to have some drive towards variety.
I had thought randomness would serve this purpose -- to pick melodies that score highly on a metric, rather than to strictly maximize it. My experiements in this direction have so far failed. The results are too arbitrary, the variety too meaningless.
So an approach I am now looking into is to build a drive for variety into the metric itself. If a note is repeated too often (or an interval or a note sequence or such), it starts scoring worse.
Results so far have not been anything I would call music. However they do not have the arbitrariness of direct insertion of randomness, and yet are neither a trivial form of variety that is itself quickly tiresome to the ear. The results are suitably pseudo-random with even simple requirements for diversity. A further and unexpected effect: one learns that the system hates repetition, so that if there is a section of repetition an effect of tension is created as one waits for it to snap and do something different.
I think this is promising. Electronic akathisia: I will torture a melody out of my computer yet.
To flesh things out a bit more:
Repetition of recent things is more irritating than repetition of less recent things. Indeed repetition or more distant things can be pleasant -- see the return to the tonic at the end of a melody.
This might be reflected in some kind of time based function for how much weight should be given to past notes. The weight can not die away too slowly into the past, or the composer will be driven eventually to atonal flights of melodic madness in its quest for novelty, but neither can it die away too quickly into the past or the output will become repetitious. 1/t seems good, based on some experimentation.