I have created a random number generator using gettimeofday() function, in C. Now,I need to evaluate this using statistical or empirical methods developed by Knuth. I searched exhaustively for the same, but could not find a workable solution. Or I may be wrong. Please help me in evaluating this RNG according to the above standards.
#include <sys/time.h>
#include <time.h>
#include <stdlib.h>
#include <stdio.h>
int* randgen(int num, int limit){
char buffer[30];
struct timeval tv;
time_t curtime;
gettimeofday(&tv, NULL);
int* numbers = malloc(sizeof(int)*num);
int i = 0;
int j;
while(num != 0){
gettimeofday(&tv, NULL);
for(j = 0; j < 1000; j++);
numbers[i] = tv.tv_usec % (limit+1);
num--;
i++;
}
return numbers;
}
int main(void)
{
FILE *fp;
fp = fopen("random.txt","w+");
printf("\nEnter the number of random integers needed\t:\t");
int num;
scanf("%d",&num);
printf("\nEnter the MAX limit for the random numbers\t:\t");
int limit;
scanf("%d",&limit);
int* result = randgen(num,limit);
int i = 0;
printf("\n");
for( i = 0 ; i < num ; i++ ){
printf(" %d ",*(result+i));
fprintf(fp,"%d ",*(result+i));
}
return 0;
}