David Mamet was asked once where he got his ideas, and he said 'my brain.' (I think this is a true and not apocryphal story- and even if not true, it has a truth to it.)
Which is sort of what makes writing so potentially difficult. The one thing you need to write is what gets in the way of your writing. Which is why there are so many books on how to write; that is, there are reams and reams about how to just get writing, not even counting all that is written about proper grammar, conflict, character development, etc... Because the best ideas come from the subconscious, and are wonderfully messy, and usually- and hopefully- not fully open to rational thought. Once you get thinking about things too much, or over analyzing, you get into serious trouble: either writer's block, or else writing that comes purely from the intellect, which is usually soulless and boring.
I think there are two ways to get around this problem. One is to do something else besides writing. Get a job, get a life, help other people, volunteer in a shelter, work on a sheep farm, explore the arctic, whatever. All these things get you out of your head, and build a foundation of experiences your subconscious can play with.
The other way to get around this problem is to have a routine for writing. If there is a common denominator to writers on writing, it is to have some sort of routine. If you write three hours in the morning after having a cup of tea and staring out the window, that's your routine. If you drink a couple of shots of bourbon and smoke unfiltered cigarettes at two in the morning as you scribble or type on your fire escape, that's your routine. Never wait for inspiration, it doesn't come on its own. Even on the days you spend that time in the morning or late at night on your fire escape writing mostly crap, inspiration will get poked and prodded.
A few other things that help are to write fast- especially dialogue, so the brain doesn't have time to get in the way. You want the characters to be writing the dialogue, not you. Also, write the first draft with 'the door closed' as Stephen King says (and if there is one writer who knows how to get writing done, it's Stephen King). You don't want the higher cortex part of your brain, that critical part, to stop you. Save that for the re-writes.
[Even though this blog is ostensibly about getting writing done and not just thinking about writing, I wanted to give a shout-out to a really great book: Light the Dark: Writers on Creativity, Inspiration, and the Artistic Process by Joe Fassler. Top-notch writers discuss their favorite literary passages, and talk about how these words inspired them. Which may sound slightly cheesy, but it's really not. Based on The Atlantic magazine's 'By Heart' series.]