Beruflich Dokumente
Kultur Dokumente
Implementation any one of the frequency test for the random number generated from the
function Rand(),conclude whether the generated random number are acceptable or not.
Conditions:
K-S test: Generate 20 random numbers and consider the significance value =0.5
Chi-square test: Generate 20 random numbers and consider the significance value =0.5
Solution:
K-S test
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include<time.h>
int main()
time_t t;
srand((unsigned) time(&t));
printf("Kolmogorov Test\n");
int n;
float dvalue1;
n=20;
float num[n];
num[i]=(rand() %50);
if(num[i]>num[j])
num[i] = num[j];
num[j] = temp;
printf("%0.2f\n",num[i]);
dp = dplus(num, n);
dn = dminus(num, n);
printf("\ndp = %f",dp);
printf("\ndp = %f",dn);
if(dp>dn)
dvalue1 = dp;
else
dvalue1 = dn;
printf("\nCalculated D = %0.2f",dvalue1);
}
else
return 0;
float data[n];
int count=1;
while(count<=n)
data[i] = ((count/n)-num[i]);
count++;
return lar;
float data[n];
int count=1;
while(count<=n)
data[i] = (num[i]-((count-1)/n));
count++;
return lar;
if(data[0]<data[i])
data[0] = data[i];
return lar;
Output:
Kolmogorov Test
14.00
16.00
17.00
23.00
30.00
30.00
31.00
31.00
32.00
34.00
36.00
39.00
39.00
41.00
43.00
44.00
44.00
47.00
47.00
49.00
dp = 0.000000
dp = 14.000000
Calculated D = 14.00
Chi-Square Test
#include
<stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
int main(){
long long int i, dim;
char expected[LEN], observed[LEN];
FILE *input;
printf("\nEnter the file name (or path) with the expected data: ");
fgets(expected,sizeof(expected),stdin);
expected[strlen(expected)-1] = 0;
printf("\nEnter the file name (or path) with the observed data: ");
fgets(observed,sizeof(expected),stdin);
observed[strlen(observed)-1] = 0;
fclose(input);
fclose(input);
printf("Computing...\n");
free(vect1x);
free(vect1y);
free(vect2x);
free(vect2y);
return 0;
}
return sum;
}
return sumSquare;
}
return sum;
}
sigma = sqrt(sum/(N-1));
return sigma;
}
fclose(input);
return lines;
}
Output: