Random random = new Random(); double mean = 0.0; double stddev = 1.0; double randomNumber = (stddev * random.NextDouble() * Math.Sqrt(-2.0 * Math.Log(random.NextDouble()))) + mean;
Random random = new Random(); double[] values = new double[100]; for (int i = 0; i < values.Length; i++) { double mean = 10.0; double stddev = 2.0; double randomNumber = (stddev * random.NextDouble() * Math.Sqrt(-2.0 * Math.Log(random.NextDouble()))) + mean; values[i] = randomNumber; }This code generates an array of 100 random numbers with a mean of 10 and standard deviation of 2. It uses the same Box-Muller transform as Example 1, but loops through the array to generate multiple numbers. The System.Random.NextGaussian method is not an actual method in C#, but the Box-Muller transform can be used to generate normally distributed random numbers. The System namespace in the .NET Framework provides the necessary classes and methods to accomplish this.