Created
May 29, 2013 03:59
-
-
Save o11c/5667876 to your computer and use it in GitHub Desktop.
A really WTF way of generating a random entry out of a list of numbers.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
int main(int argc, char **argv) | |
{ | |
int fd = open("/dev/urandom", 0); | |
int ai = 0; | |
int idx; | |
for (;;) | |
{ | |
char c; | |
read(fd, &c, 1); | |
if (ai && argv[ai][idx + 1] == c) | |
{ | |
printf("++ %d %d\n", ai, idx); | |
idx++; | |
if (idx == strlen(argv[ai])) | |
break; | |
} | |
for (int i = 1; i < argc; ++i) | |
if (argv[i][0] == c) | |
{ | |
printf("-> %d %d\n", ai, idx); | |
ai = i; | |
idx = 0; | |
} | |
} | |
puts(argv[ai]); | |
return ai; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment