diff --git a/2020/random b/2020/random new file mode 100755 index 0000000..d53ab32 Binary files /dev/null and b/2020/random differ diff --git a/2020/random.c b/2020/random.c new file mode 100644 index 0000000..8e742ca --- /dev/null +++ b/2020/random.c @@ -0,0 +1,27 @@ +#include +#include +#include + +int main(void) { + char date_string[11]; + time_t tm = time(NULL); + struct tm* local = localtime(&tm); + + // Seed the randomizer with the current date + strftime(date_string, sizeof(date_string), "%G %m %d", local); + + int sum = 1; + for(int i=0; date_string[i]; i++) + sum = sum * date_string[i]; + + srand(sum); + + // Pick a random item from the list + char* list[] = { + "C", "D", "F#", "Racket", "Pascal", + "PureScript", "Rust", "fish" + }; + int length = sizeof(list) / sizeof(list[0]); + int num = rand() % length; + printf("Your lucky language is %s\n", list[num]); +}