C++随机生成整数测试磁盘文件排序
#include <iostream> #include <time.h> #include <assert.h> using namespace std; const int size=10000000; int num[size]; int main() { FILE *fp=fopen("data.txt","w"); assert(fp); for(int n=1; n <= size; n++) { num[n]=n; } srand((unsigned)time(NULL)); for (int n=0; n < size;n++) { int i=(rand()*RAND_MAX + rand())%10000000; int j=(rand()*RAND_MAX + rand())%10000000; swap(num[i],num[j]); } for (int n=0; n < size; n++) { fprintf(fp,"%d ",num[n]); } fclose(fp); return 0; }