as cliched as it sounds Id have to agree with patkk
however for me its usually the core core melody that comes out of my head,
and then I gradually add structural elements to it,
sort of like writing a book, the thesis comes out of the blue as an idea, and then you build around it, delete parts, move things around so it makes sense until you have the final thing, the name of the piece. :P
I mean ive also never composed a piece without a reason either,
usually there's been some sort of catharsis involved.
Ive never been able to "compose on command" or it sounds forced or I get bored and do not continue with it.
I wouldn't say there's any right or wrong way to do it though,
for instance my knowledge of actual music theory in terms of names, "equations" ect, is novice at best,
which is why Ive always done things by ear on the piano roll or on my keyboard. Many composers & musicians would consider that an outrage, even in 2008
but for me Ive always been able to achieve what I wanted to in that medium
The only real backfall is the timing can be tricky and you have to be incredibly careful on where you are placing things,
but even then there are ways around that hurdle.
anyhow now im getting on a rant lol
but the point is, i think its really about how need to achieve your goal/message/catharsis, and there is no right or wrong way to do that, you have to make choices as an artist that a right for yourself.
Some people take music from mathematician's perspective & others from a painter's perspective , ect ect. Thats what makes music so great! It can involve so many different levels of rationale and feeling in its creating process that it allows immense versatility, and it all depends on who is the one creating it and their personal beliefs/influences/emotions/muses/subconcious.
For me I find a lot if it is from the later, the subconscious, its sort of my way to communicate with things I may not usually let out or even be aware of on a daily basis. Like a musical dream catcher. How i do that, i dont really know, but it starts with an idea & builds from there, and at the end i feel relieved.