Skip to content

Instantly share code, notes, and snippets.

@rjzak
Created July 24, 2013 14:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rjzak/6070996 to your computer and use it in GitHub Desktop.
Save rjzak/6070996 to your computer and use it in GitHub Desktop.
Generate & store random data in a file. Designed to create a large random file to use as a key file for TrueCrypt.
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
int main(int argc, char* argv[] ) {
if (argc != 3) {
printf("Error, you must provide a destination file and number of iterations\n");
return -1;
}
FILE *fp;
int i = 0;
srand(time(NULL));
const int iters = atoi(argv[2]);
printf("Writing %d number of times...\n", iters);
fp = fopen(argv[1], "w");
for(i = 0; i < iters; i++) {
int d = rand();
int s = rand() % 2;
d = d << s;
s = d % 100;
d = d / 2;
fwrite(&d, sizeof(d), 1, fp);
fwrite(&s, sizeof(s), 1, fp);
//printf("Writing: %d %d\n", d, s);
}
fclose(fp);
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment