随机生成1000w内不重复的随机数


http://blog.csdn.net/v_july_v/article/details/6630757

从上面博客中获取的算法,编译测试通过

 

void testMake1000WRand() { const int size = 10000000; int *num = new int [size]; int n; FILE *fp = fopen("F:\\rasterTest\\data.txt", "w"); assert(fp); for (n = 1; n <= size; n++) num[n-1] = n; srand((unsigned)time(NULL)); int i, j; for (n = 0; n < size; n++) { i = (rand() * RAND_MAX + rand()) % 10000000; j = (rand() * RAND_MAX + rand()) % 10000000; swap(num[i], num[j]); } for (n = 0; n < size; n++) fprintf(fp, "%d\t", num[n]); fclose(fp); delete num; return ; }

你可能感兴趣的:(算法,File,测试,null,delete,FP)