Drawing a random number from a standard normal distribution using standard rand () functions

Thus, most programming languages ​​contain the rand () function, thanks to which you can generate a random number from 0 to 1 ....

My question is, is there a way to manipulate this standard rand () function so that you can instead draw a random number from a normal distribution with mean and standard deviation?

Note that I am not asking if the language has a normal distribution function, I am asking if you can "simulate" drawing a normal random distribution variable using the rand () function ...

0
source share
1 answer

, ( ):

    static Random r = new Random();
    static double Normal(double mu, double sig)
    {
        double u, v, x, y, q;
        do
        {
            u = r.NextDouble();
            v = 1.7156 * (r.NextDouble() - 0.5);
            x = u - 0.449871;
            y = Math.Abs(v) + 0.386595;
            q = Math.Sqrt(x) + y * (0.19600 * y - 0.25472 * x);
        } while (q > 0.27597 && (q > 0.27846 || Math.Sqrt(v) > -4.0 * Math.Log(u) * Math.Sqrt(u)));
        return mu + sig * v / u;
    }
+1

All Articles