/* xrandom.c */

#include <stdio.h>
#include "random.h"

/*
	test urand() R times, by N trials uniformly filling M bins
	print bin occupancies and report chi-square statistic
*/

int main()
{
	const int M=10, N=1000, R=5;
	int i, j, a[M];
	double v, y;
	
	usrand (0);
	for (i=0; i<R; ++i) {
		for (j=0; j<M; ++j) a[j] = 0;
		for (j=0; j<N; ++j) ++a[urand() % M];
		for (j=0; j<M; ++j) printf("%4d", a[j]);
		
		v = 0.0;
		y = N, y /= M;
		for (j=0; j<M; ++j) v += (a[j] - y) * (a[j] - y) / y;
		printf("\n%d degrees of freedom\n", M-1);
		printf("chi-square statistic = %6.2f\n\n", v);
	}
}