Kolmogorov  Smirnov test — a very effective way to determine if two samples differ significantly from each other. Usually used to check the uniformity of random numbers. Homogeneity is one of the most important properties of any random number generator, and the Kolmogorov  Smirnov test can be used to test it.
The KolmogorovSmirnov test can also be used to test whether the two underlying onedimensional probability distributions are different. This is a very effective way to determine if two samples differ significantly from each other.
The Kolmogorov – Smirnov statistic quantifies a distance between the empirical distribution function of the sample and the cumulative distribution function of the reference distribution, or between the empirical distribution functions of two samples.
To use the test to test the uniformity of random numbers, we use the CDF (cumulative distribution function) U [0, 1].
F (x) = x for 0 "= x "= 1
Empirical CDF, Sn (x) = (number of R1, R2 .. .Rn "x) / N array of random numbers
, random numbers must be in the range [0, 1].
The hypothesis used is —
H _{ 0 } (null hypothesis): null hypothesis assumes that the numbers are evenly distributed between 01.
If we can reject the null hypothesis, it mean s that the numbers are unevenly distributed between 01. Failure to reject the Null Hypothesis, although does not necessarily mean the numbers follow a uniform distribution.
The kstest
Function in Scipy Python —
Parameters :
Statistics: This is the calculated value of D, where
D =  F (x ) Sn (x) 
.
" This D is compared with D _{ alpha } where alpha is the level of significance. Alpha is defined as the probability of rejecting the null hypothesis given the null hypothesis (H _{ 0 }) is true. For most of the practical applications, alpha is chosen as 0.05.pvalue: This is calculated with the help of D.
" If pvalue" alpha, we fail to reject the null hypothesis. Otherwise, we conclude that the numbers are not uniform. Ideally, the pvalue should be as large as possible. For perfect uniform distribution pvalue = 1 and Statisitics = 0.

Exit:
KS Test — this is a very powerful way to automatically distinguish samples from another distribution. The kstest function can also be used to check if the data follows a normal distribution or not. It compares the observed and expected cumulative relative frequencies of the normal distribution. The KolmogorovSmirnov test uses the maximum absolute difference between the observed and expected cumulative distribution.
 The null hypothesis used here assumes that the numbers follow a normal distribution.
 The function remains exactly the same ... Again, it returns statistics and a pvalue. If the p value is "alpha, we reject the null hypothesis.

Exit: