srand((unsigned)time(NULL)); std::vector hour;//时 std::vector minute;//分 std::vector second;//秒 std::vector vSecond;//总秒数 int n = 5000;//随机个数 for (int i = 0; i < n; i++) { int _second = rand() % 18000; vSecond.push_back(_second); } for(int i =0 ; i< n-1; ++i) { for(int j = 0; j < n-i-1; ++j){ if(vSecond[j] < vSecond[j+1]) { int tmp = vSecond[j] ; vSecond[j] = vSecond[j+1] ; vSecond[j+1] = tmp; } } } for (int i = 0; i < n; i++){ hour.push_back(vSecond[i] / 3600); minute.push_back(vSecond[i] / 60 % 60); second.push_back(vSecond[i] % 60); } FILE *f; f = fopen("Time.csv" , "wb"); for (int i =0; i< n; i++) { fprintf(f,"%d, %d, %d\n", hour[i], minute[i], second[i]); } fclose(f);