note
moklevat
To add to blue_cowdawg's advice, if you need to roll your own, what you are seeking is the <a href="http://en.wikipedia.org/wiki/Chi-squared_distribution">probability density function of the chi-squared distribution</a>, which is given <a href="http://upload.wikimedia.org/math/f/0/5/f0505830d120bf28c0cd2decc52ac413.png">here</a> where x is the chi-square value and k is the number of degrees of freedom, and you will need to include values from the <a href="http://en.wikipedia.org/wiki/Particular_values_of_the_Gamma_function">Gamma function</a>, which has a closed form solution for half-integer value (i.e. k/2).
1017275
1017275