However, for my application, I need integers instead of doubles. So my question is, how would you generate the equivalent of the above but for integers instead of doubles? One possible path to take is to convert the doubles into integers in some fashion, but I don't know enough about how the random library works to know whether this can be done in a fashion that really preserves the bell shape and the mean/std. deviation.

I should mention that the goal here is not so much randomness, as it is to get a set of integers of a specific size, with the correct mean and std. deviation.

Ideally I would also like to specify the minimum and maximum values that can be produced, but I have not found any way to do this even for doubles, so any suggestions on this are also welcome.

You did specify the minimum and maximum values... when you said "Gaussian". You either need to specify what your goals are (what you need randomness for), instead of your approach (generating "gaussian" integers), or go back and study statistics so you understand why your question makes no sense. (Among other things, to generate integers, you need a discrete distribution, but gaussian is continuous).
–
Ben VoigtJul 16 '11 at 16:40

I somewhat see your point, but I still think it makes sense. What I want to do is to generate a set of integers that are distributed over a range, satisfying a given mean and std. dev. That is the most important part, but I would also like these integers to form a bell curve, although it cannot be strictly gaussian, I would like it to preserve this property as much as possible. Maybe rounding is actually just the way then?
–
ChrKroerJul 17 '11 at 7:59

Then I suggest you compute a gaussian CDF across the range of integers you're interested in, stretch it slightly to account for the missing tails, and store it in an array. Then you generate uniform reals in the range [0:1], and use binary search to invert the CDF. This procedure for generating samples from an arbitrary CDF is pretty standard.
–
Ben VoigtJul 17 '11 at 12:42

I will try that, thanks! If you could add this to your answer below I will mark it as accepted.
–
ChrKroerJul 17 '11 at 13:31

Solve the equations for mean and variance simultaneously to get p and n. Then generate samples from this distribution.

If n doesn't come out integer, you can use a multinomial distribution instead.

Although wikipedia describes methods for sampling from a binomial or multinomial distribution, they aren't particularly efficient. There's a method for efficiently generating samples from an arbitrary discrete distribution which you can use here.

In the comments, you clarified that you want a bell-shaped distribution with specific mean and standard deviation and bounded support. So we'll use the Gaussian as a starting point:

compute a gaussian CDF across the range of integers you're interested in

offset and scale it slightly to account for the missing tails (so it varies from 0 to 1)

store it in an array

To sample from this distribution:

generate uniform reals in the range [0:1]

use binary search to invert the CDF

As the truncation step will reduce the standard deviation slightly (and affect the mean also, if the minimum and maximum aren't equidistant from the chosen mean) you may have to tweak the Gaussian parameters slightly beforehand.

I suppose some naive way of doing this is generating uniform numbers from [-1, +1] and adding up N of them to get numbers in the range [-N, +N]. This would produce a very different distribution than a Gaussian though.
–
Mike BanteguiJul 16 '11 at 16:52

@Mike: If those are continuous random variables, their sum will have a distribution very similar to Gaussian (by the central limit theorem). If you meant drawing from the discrete set {-1, 1}, then yeah it will be very non-Gaussian (although the CDF will still be quite close to a Gaussian).
–
Ben VoigtJul 16 '11 at 16:59

Yes, I meant the set {-1, +1}, not reals. He would be able to set the mean and standard deviation as well by rescaling the output, but forcing arbitrary minimum and maximum values would be tricky.
–
Mike BanteguiJul 16 '11 at 17:05