I'm an amateur composer, not trained, and only write small pieces from time to time mainly for my own enjoyment. Either just short melodies for solo instrument or sometimes keyboard pieces suitable for a beginner, or short compositions of a few minutes for maybe 3 or 4 instruments.
This is perhaps one of my best pieces, for violin and viola.
It's actually improvised in real time with one hand playing each instrument on a keyboard which was split so left half of the keyboard played viola and right half played violin -on virtual instruments.
Anyway, I thought I'd add a few things I've found out which may help others, perhaps especially if in same situation as me, beginners just starting out.
One exercise I did for several years was to write a melody just about every day. I just wrote out whatever came to mind. And not spend ages polishing it, and not bothered if it is good or bad, nobody else needs to see it except yourself.
After perhaps five or ten minutes work on it, whatever you have - that's it.
That helps a lot with spontaneity. Composing music doesn't have to be difficult. It can be easy and spontaneous and fun.
So- that's not going to take you all the way to composing a symphony obviously and I've no idea how you do that, and don't know how far you can take it. But if you just want to write short pieces for your enjoyment it can take you that far.
Gradually - well I found anyway - process of composing gets more spontaneous and fun.
I think it is possible it might also be useful as an exercise for fully trained musicians and composers too as a way to connect back to that ground of enjoyment of what you are doing, and why you are doing it.
And surprising how often you come back to something later which seemed so obvious at the time you wondered why you bothered to write it down, and later you think "actually that's rather good".
When you are in the moment of composition you are a bit too close to it to really appreciate what you are writing, or can be.
I also compose out of doors, when I can, take my recorder with me, play a few notes and write down whatever comes to mind.
I'm not speaking from my own experience obviously, but it seems that even writing long pieces can have this element of spontaneity from examples of composers who have written like this.
Handel for instance wrote the Messiah in 24 days, and the score shows signs of being written rapidly.
Also though, you might like algorithmic composition.
So, this is Tune Smithy, a program I wrote which creates music using a fractal, like the visual fractals. It's not based on traditional composing methods, at all. It's a kind of transformed automatic sloth canon.
This won't help you with traditional composition, any more than the Mandelbrot explorers help you develop as a visual artist.
But it lets you experiment with instrumentation, and have fun with composition, and lets you create complex pieces that continue for as long as you like. You change the piece by tweaking parameters, a bit like the way you adjust a visual fractal.