程序代码:
#include <stdio.h> #include <stdlib.h> #include <time.h> #define AMOUNT 50000000 int main() { FILE * fpnum=fopen("numout.txt","w+"); FILE * fpstr=fopen("strout.txt","w+"); int num=0; char ch; int i; for(i=0;i<AMOUNT;i++) { if(!(i%1000)) srand((unsigned)time(NULL));//每产生1000个后,重设随机数种子 num=rand()%8; fprintf(fpnum,"%d",num); switch(num/2) { case 0: ch='A'; break; case 1: ch='B'; break; case 2: ch='C'; break; case 3: ch='D'; break; } fputc(ch,fpstr); } fclose(fpnum); fclose(fpstr); return 0; }