A lot of the riffs I come up with come from me fucking up someone else's song. Like I'll be sitting there jamming out to Master of Puppets or Creeping Death or something along those lines, and I'll miss a chord change or hit the wrong note at the wrong time. sometimes I punch myself in the face when that happens, but most often, I just go with it, and see where it takes me. I've come up with a lot of riffs like that, and they sound nothing like the original song that I was playing(Though they are very thrashy.)
Another thing I do is I just start tremolo picking a certain note and try to find the best note to follow it, then the best note to follow that, etc. A lot of stuff I write is tremolo picked or a triplet rhythm, but a lot of times I come up with a cool progression and change it up a bit, like adding a few low E's(or C's depending on which guitar I'm playing) or playing it in power chords or minor third chords instead of single notes.
So just fuck around. constantly. And if you got something that sounds cool, don't automatically play it the way you originally did. Mess around with it. Play it in chords instead of single notes, and vice versa. Try to find the best interval for it, and harmonize it. Stuff like that