Before you can design your random number generator you need to specify the distribution it should draw from. You've only partially done that: i.e., you specified it draws from integers in [1,9] and that it has a mean that you want to be able to specify. That still leaves an infinity of distributions to chose among. What other properties do you want your distribution to have?
Edit following comment: The mean of any finite sample from a probability distribution - the so-called sample mean - will only approximate the distribution's mean. There is no way around that.
That having been said, the simplest (in the maximum entropy sense) distribution over the integers in the domain [1,9] is the exponential distribution: i.e.,
p = @(n,x)(exp(-x*n)./sum(exp(-x*(1:9))));
The parameter x
determines the distribution mean. The corresponding cumulative distribution is
c = cumsum(p(1:9,x));
To draw from the distribution p
you can draw a random number from [0,1] and find what sub-interval of c
it falls in: i.e.,
samp = arrayfun(@(y)find(y<c,1),rand(n,m));
will return an [n,m]
array of integers drawn from p
.