How can I generate random numbers that follow a student-t distribution? From several sources I understand that this can be done using a random sample of size $n$ drawn from a normally distributed population, as follows:
$$ t = \frac {(x - m)} {(s/\sqrt n)} $$
Where $x$ is the sample mean, $m$ is the mean of the normal distribution (I assume you can just use the standard normal distribution, so $m=0$?), and $s$ is the sample standard deviation.
The degrees of freedom of the student-t distribution will then be $n-1$.
Do I understand correctly that in order to generate a random student-t value with $f$ degrees of freedom, I should first generate $f+1$ normally distributed values (i.e. standard normal), and then calculate the mean ($x$) and standard deviation ($s$) of these and apply the above formula? And if I do this repeatedly many times, the resulting random values will approach a student-t distribution with $f$ degrees of freedom?
I tried this in Excel using a macro that uses the above formula and another macro that generates random Gaussians (which works, I tested it) but the resulting random values do not seem to be completely student-t distributed. For instance with 6 degrees of freedom, the variance of 10,000 random values is about $1.7$ while it should be $6/(6-2) = 1.5$.