This question might belong to stats.SE or cs.SE or SO, so please help me find the correct final location.
I wish to create $N$ gaussian random integers with $\mu=0$ and some $\sigma$ where their summation is equal to zero.
Currently I employ the following strategy:
- Create $N$ gaussian random numbers
- Round them to the nearest integer
- Sum them
- If summation is not close to zero, goto 1
- If summation is close to zero, say $m$, choose $m$ random numbers among $N$ and reduce/increase these by one.
This way, I trade off the summation with $\mu$ of the distribution. I need some computational efficiency so I cannot retry each time the summation is not zero.
So, what is the best way to generate such gaussian random numbers?
Using R statistical software, I will show how to do transform $n = 1000$ (continuous) normal random variables randomly sampled from $\mathsf{Norm}(\mu = 100, \sigma = 10)$ so that they are standard normal.
So the random variables $S_i$ have essentially 0 sample mean; that is, the mean is an underflow not distinguishable from 0.
You do not say what you mean by 'Gaussian random integers'. However, rounding seldom affects sample means or variances by very much. So if you round the $S_i$ to get integers $Z_i,$ then these integers will have very nearly mean 0 and variance 1. (I am not sure there is a way to 'adjust' the $Z_i$ to get such integers from the same distribution exactly with mean 0 and variance 1.)
The graph below shows a histogram of the 1000 integer values along with the standard normal density curve.
Notes: (1) Whatever you mean by 'Gaussian random integers', I am skeptical about your step (5) because it will result in a mixture of two distributions (which will be very nearly the same, nevertheless clearly different). (2) You seem to use $\mu$ for both population mean and sample mean. Please clarify that notation.
Depending on your requirements, another method might be to use the fact that symmetrical binomial distributions are nearly normal. If $X \sim \mathsf{Binom}(n=4, p= 1/2),$ then $E(X) = 2$ and $SD(X) = 1.$ So integers $Z = X -2$ might meet your requirements.
Below is a histogram of these 1000 observations along with the standard normal density curve.