This is one of the most common questions I get asked and I suspect this is true for most writers, regardless of gendre. I also suspect that almost every writer couldn't tell you exactly. I find that most of my ideas come as a bit of an "aha" moment where something clicks in my feeble little cranium and an idea pops out. I always carry paper with me since I have a good memory - it's just short. Nothing worse than loosing the idea for the next blockbuster story for the lack of a scrap of paper.
I find I get most of my ideas when I'm not really thinking about it. Mowing the lawn, road trips with music on, are all fertile places for me. However, contrary to that, the idea for my second book did come as an "aha!" moment with the bulk of the story in place instead of a scrap of an idea. I was looking at a drawing my friend and illustrator, the brillant Jennifer Aikman-Smith, did of a baby dragon looking up at you holding a valentine. He had the big puppy dog eyes and "pop" came the idea for "Emily Finds a Dragon" with 75% of the story dragging along behind.
That was unusual for me. Most of my stories come in a series of movie scenes in my head. I jot them down and eventually pull the pieces together to make the first draft. As a result, I often have two or three manuscripts going at the same time. One I focus on, one that is ruminating in my head and I pick out scenes for, and one that I'm researching. Since my writing time is often hit and miss, this allows me to do something constructive with my writing time regardless of how long I have or how tired I am. Sometimes I'm just typing notes into the computer. This is good stuff to be doing when I'm too tired to be really creative, but I'm still doing something that needs to be done.
I suspect this doesn't work for many writers, but it does for me. I have had to juggle time all my working career so I'm used to trying to work on a couple of things at a time. As I get older, and slowly back out of the many organizations I volunteer for, I hope to have a more structured day where I can block off time to write at more consistant times. Then I hope I coan concentrate mainly on one manuscript at a time.