Generating random numbers is a vast topic. But since you said it's a simple simulation, here's a simple approach to get going:
Generate several (say n
) random numbers uniformly distributed on (0, 1). The built-in function Math.random
can supply those numbers.
Add up those numbers. The sum has a distribution which is approximately normal, with mean = n/2
and standard deviation = sqrt(n)/sqrt(12)
. So if you subtract n/2
, and then divide by sqrt(n)/sqrt(12)
, you'll have something which is approximately normal with mean 0 and standard deviation 1. Obviously if you pick n = 12
all you have to do is subtract 6 from the sum and you're done.
Now to get any other mean and standard deviation, just multiply by the standard deviation you want, and add the mean you want.
There are many other ways to go about it, but this is perhaps the simplest. I assume that's OK given your description of the problem.