Example: Random Number Generation

In this example, a discrete normal random sample of size 1000 is generated via NextNormal . After the ChiSquaredTest constructor is called, the random observations are added to the test one at a time to simulate streaming data. The Chi-squared test is performed using Cdf.Normal as the cumulative distribution function object to see how well the random numbers fit the normal distribution.
using System;
using Imsl.Stat;

public class RandomEx1 : ICdfFunction
{
	public double CdfFunction(double x) 
	{
		return Cdf.Normal(x);
	}

	public static void  Main(String[] args)
	{
		int nObservations = 1000;
		Imsl.Stat.Random r = new Imsl.Stat.Random(123457);
		ICdfFunction normal = new RandomEx1();
		ChiSquaredTest test = new ChiSquaredTest(normal, 10, 0);
		for (int k = 0; k < nObservations; k++)
		{
			test.Update(r.NextNormal(), 1.0);
		}
		
		double p = test.P;
		Console.Out.WriteLine("The P-value is " + p);
	}
}

Output

The P-value is 0.496307043723263

Link to C# source.