I would say I rarely hear things in my head..... If an interesting phrase results, I remember what I played and can build upon it. Thats where it is not random. Sometimes I remember these things and can bring them back later in an improvisation. As Ted mentions, sometimes these ideas just "stick" and they start to accumulate into a composition.
This process you describe requires close listening to what you are playing. To define an interesting phrase requires you to be able to hear it, the thing is a lot of people can't do this because they think it is completely about what the hands have to do. It isn't the fact, the hands may play randomly on a form, but the ear has to control it. I find giving improv students Cd's from Jazz greats and offering tools for them to reproduce what they are listening to by ear (and alter it to their liking), naturally increases their ability.