Talk:Algorithm Implementation/Pseudorandom Numbers/Chi-Square Test

The algorithm presented here does not include terms in the summation for empty bins. If the count for a bin is 1, an entry appears in the hashtable, and a term is added to the summation: (1 - N_r)2. If the count for a bin is 0, no entry appears in the hashtable, and therefore a term is not added which would have been: (0 - N_r)2. I therefore suggest that use of a hashtable for accumulating the counts is not helpful -- an array would correctly capture the empty bins.

If the distribution is uniform, none of the bins should be empty, and the chi-square value should be correct. If the distribution is not uniform, some bins could be empty, and the chi-square value will not be correct, but may not be far enough away from the expected value to indicate that the distribution is not uniform.

Incidentally, this algorithm also does not assert that the number of values outside of the allowed range is zero (expected count is zero, but actual is non-zero).