Looking at some legacy code in our app, found this weird implementation of Normal RNG. I want to swap it for a proper Box-Muller transformation but need some encouragement.
As you can see, it generates 5 random numbers from -3.875 to +3.875 and then averages them out to get a quasi-normally distributed value from -1 to +1. Can this possibly be right? How can this even work? Why 5 samples?
Someone, please explain this:
private double GetRandomNormalNumber()
{
const double SPREAD = 7.75;
const double HALFSPREAD = 3.875;
var random = new Random();
var fRandomNormalNumber = ((random.NextDouble()*SPREAD - HALFSPREAD) +
(random.NextDouble()*SPREAD - HALFSPREAD) +
(random.NextDouble()*SPREAD - HALFSPREAD) +
(random.NextDouble()*SPREAD - HALFSPREAD) +
(random.NextDouble()*SPREAD - HALFSPREAD)
)/5;
return fRandomNormalNumber;
}