mardi 12 juillet 2016

Gaussian Random number generator seems not to be working

i have a method that generates random numbers but doesn't seem to be following a Gaussian distribution, to further complicate this i am returning values as a 'byte'. I really have no idea how this algorithm works, i tried researching on wikipedia but to little avail. Does anyone know why this doesn't seem to be working?

        private byte RndGaussian(byte mean, byte stdDev)
    {
        // From stackoverflow user 'yoyoyoyosef'.
        double u1 = rnd.NextDouble(); // These are uniform(0,1) random doubles
        double u2 = rnd.NextDouble();
        double randStdNormal = Math.Sqrt(-2.0 * Math.Log(u1)) * Math.Sin(2.0 * Math.PI * u2); // Random normal(0,1)
        byte randNormal = Convert.ToByte(mean + stdDev * randStdNormal); // Random normal(mean,stdDev^2)
        return randNormal;
    }




Aucun commentaire:

Enregistrer un commentaire