Random music note generation

I'm working on a little project, which is in early development stage right now. What I'm trying to figure out is how do I generate random music, especially notes. By googling I've only managed to find ransom note generator and lots of random music, where word random has nothing to do with definition of random variable :) I don't know if anybody have done this before and I wish to know about presence of such work to give me some guidance. Here some of my naive ideas:

Given the root note of the chord generate a random note with mean of that note and some deviation, which might be controlled by part of the bar which you are currently in.

I would prefer to set 0 as a reference to root note in every bar and generate integers, which would mean how many scale intervals up or down melody should deviate from the root. But this approach might make joining melody bars together harder, so another idea is to use the key of whole part as a reference note and then change the mean of random variable according to which bar corresponds to which key.

So now, that I have explained a little on how do I expect the mean of the random note to be, lets move on to random number generation in the bar or a piece of music. What I need is a sequence of integers with mean $0$. Natural candidates could be

1. Sum of two Poisson distributed variables, one of them should be multiplied by $-1$
2. The same thing with binomial random variables.

Maybe you can suggest something better?

For the rhythm generation I will probably set the fixed number of maximum notes per bar and then generate sequence of zeroes and ones, the one will indicate that beat is changing. Maybe I will will set probability of zero conditional on how many zeroes were before. If anybody has ideas I would love to hear them!