mirror of
https://github.com/Kaehvaman/OAIP.git
synced 2025-03-15 06:06:21 +04:00
generate random files
This commit is contained in:
parent
767c4c1874
commit
62c25a7564
@ -292,31 +292,43 @@ int clip(int n, int lower, int upper) {
|
|||||||
return max(lower, min(n, upper));
|
return max(lower, min(n, upper));
|
||||||
}
|
}
|
||||||
|
|
||||||
void createRandomBinFiles(int n, int minsize, int maxsize) {
|
void createRandomBinFiles(int n, int size) {
|
||||||
return;
|
if (size <= 0) {
|
||||||
|
puts("size can't be less than 1");
|
||||||
if (minsize <= 0 || maxsize >= INT_MAX || maxsize < minsize) {
|
|
||||||
puts("Incorrect minsize or maxsize");
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
for (int i = 0; i < n; i++) {
|
for (int i = 0; i < n; i++) {
|
||||||
int size = clip(rand(), minsize, maxsize);
|
unsigned char* pa = (int*)malloc(size);
|
||||||
|
|
||||||
int* pa = (int*)malloc(size);
|
|
||||||
if (pa == NULL) {
|
if (pa == NULL) {
|
||||||
puts("Out of memory");
|
puts("Out of memory");
|
||||||
exit(EXIT_FAILURE);
|
exit(EXIT_FAILURE);
|
||||||
}
|
}
|
||||||
|
|
||||||
for (int i = 0; i < size; i++) {
|
for (int i = 0; i < size; i++) {
|
||||||
|
pa[i] = (unsigned char)rand();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
char path[_MAX_PATH];
|
||||||
|
sprintf_s(path, _MAX_PATH, "randbin\\bin%d", i);
|
||||||
|
|
||||||
|
FILE* file = fopen(path, "wb");
|
||||||
|
if (file == NULL) {
|
||||||
|
puts("Failed to create file");
|
||||||
|
exit(EXIT_FAILURE);
|
||||||
|
}
|
||||||
|
|
||||||
|
fwrite(pa, sizeof(unsigned char), size, file);
|
||||||
|
|
||||||
|
fclose(file);
|
||||||
|
free(pa);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
int main() {
|
int main() {
|
||||||
srand(time(NULL));
|
srand((unsigned int)time(NULL));
|
||||||
|
time_t start;
|
||||||
|
time(&start);
|
||||||
|
|
||||||
//saveRandomArray();
|
//saveRandomArray();
|
||||||
|
|
||||||
@ -339,5 +351,9 @@ int main() {
|
|||||||
|
|
||||||
//task5();
|
//task5();
|
||||||
|
|
||||||
|
createRandomBinFiles(1, 1024*1024);
|
||||||
|
|
||||||
|
printf_s("time = %.0lf seconds", difftime(time(NULL), start));
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
BIN
lab19/lab19/randbin/bin0
Normal file
BIN
lab19/lab19/randbin/bin0
Normal file
Binary file not shown.
Loading…
x
Reference in New Issue
Block a user