Last active
August 29, 2015 14:10
-
-
Save spedru/c5a8d8d3778f2b071b18 to your computer and use it in GitHub Desktop.
holy shit this is stupid
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
#include <stdio.h> | |
#include <unistd.h> | |
extern long int random(void); | |
extern void srandom(unsigned int seed); | |
extern int isatty(int); | |
extern int fileno(FILE *stream); | |
extern long int strtol(const char *nptr, char **endptr, int base); | |
int main(int argc, char *argv[]) | |
{ | |
int limit; | |
if(argc != 2 || !(limit = strtol(argv[1], NULL, 10))) | |
{ | |
fprintf(stderr, "Usage: %s [INTEGER]\n", argv[0]); | |
return 1; | |
} | |
FILE *fp = fopen("/dev/urandom", "r"); | |
srandom(fgetc(fp)); | |
fclose(fp); | |
for(int i = 0; i < limit; i++) | |
{ | |
printf("\x1B[%dm%c", 30 + (int)(random() % 6 + 1), | |
' ' + (int)(random() % 94)); | |
} | |
if(isatty(fileno(stdin))) // Do not append a newline if we are being piped | |
{ | |
putchar('\n'); | |
} | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment