/* randline.c ** randomize stdio on a per-line basis ** More efficient C version ** ** address@hidden for comments. Source released to the public domain. ** Share and enjoy. Whee. */ #include #include #include #include static FILE *crypto = NULL; void initrand(void) { crypto = fopen("/dev/urandom", "r"); if (!crypto) srand(time(NULL)); } int myrand(void) { int stdlib = 0, blah; if (!crypto) return rand(); fread(&blah, sizeof(blah), 1, crypto); return blah & INT_MAX; } int main(void) { char **lines; int nlines = 0; while (!feof(stdin)) { lines = (char **)realloc(lines, (nlines + 1)*sizeof(char *)); lines[nlines] = (char *)malloc(1024); fgets(lines[nlines], 1023, stdin); nlines++; } initrand(); while (nlines) { int i = myrand()%nlines; if (strlen(lines[i])) fputs(lines[i], stdout); free(lines[i]); lines[i] = lines[nlines - 1]; nlines--; } free(lines); return 0; }