Kolmogorov-Smirnov Test

RANDOM NUMBER GENERATION
Test for Random Numbers
 Testing for Uniformity

Refer : Kolmogorov-Smirnov Goodness-of-Fit Test for more detail explanation.
Q) Write a program for implementation of Testing for Uniformity in Kolmogorov-Smirnov Test using C++ .
ANS.

/* Program for  Kolmogorov-Smirnov Test */


#include<iostream.h>
#include<conio.h>
void main()
{
    clrscr();
    int n,i;
    float r[100];
    float cvalue,d,dplus,dminus,tplus,tminus;
    dplus=0;
    dminus=0;
    cout<<“enter critical value”;
    cin>>cvalue;
    cout<<“please enter number of values”;
    cin>>n;
    for(i=0;i<n;i++)
    {
        cin>>r[i];
        tplus=float((i+1)/n)-r[i]);
        tminus=r[i]-float(i/n);
        if(tplus>dplus)
        {
        dplus=tplus;
        }
        if(tminus>dminus)
        {
        dminus=tminus;
        }
    }
    if(dplus>dminus)
    d=dplus;
    else
    d=dminus;
    cout<<d;
    if(d<cvalue)
    cout<<“uniform distribution is not rejected”<<endl;
    else
    cout<<“uniform distribution is rejected”<<endl;
    getch();
}

//output:
Enter critical value 15
Please enter number of values
2
5
6
uniform distribution is not rejected