Sometimes I'll sleep for 10 hours sleep like a log and not dream at all other times I'll take a 20 minute nap and have a long, intricate dream.

So I was wondering what is the general cause of dreaming?

Is it sheer randomness for the most part?