Learn some scales, noodle around with those scales on the piano for an hour (i mean seriously noodle like just go to town on) don't think just hit random keys, do flourishes think medieval/baroque, make sure all the random keys you're hitting are in the scale though. Record all the midi, listen back and pick out a melody from there. Don't do a minutes worth though, really just fuck around for a good 20 mins at least. Out of randomness comes patterns eventually : ) if you've got a good ear, you'll find something in the mess.