0

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;

}
4

1 回答 1

2

George Marsaglia 的测试套件仍然是一个参考。一般来说,你可以看看他的工作,有很多关于伪随机生成器和实现的所有实际方面的知识。

于 2013-01-09T19:22:24.563 回答