From: Colin Patrick McCabe Date: Sat, 13 Mar 2010 15:56:34 +0000 (-0800) Subject: random-word: Seed using gettimeofday X-Git-Url: http://club.cc.cmu.edu/~cmccabe/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=01865c491f871d5470013a28347c3e8733aab2ea;p=cmccabe-bin random-word: Seed using gettimeofday Seed using gettimeofday(2) rather than time(2). Seeding with time(2) gave some humorous results because we could get the same word back multiple times if the program was invoked multiple times a second. --- diff --git a/random-word.c b/random-word.c index b55bd1d..d751d06 100644 --- a/random-word.c +++ b/random-word.c @@ -2,7 +2,7 @@ #include #include #include -#include +#include #define DICT "/usr/share/dict/linux.words" #define STARTING_SZ 8192 @@ -91,7 +91,10 @@ int main(void) FILE *fp; const char *word; struct dict *dict; - srandom(time(NULL)); + struct timeval tv; + + gettimeofday(&tv, NULL); + srandom(tv.tv_usec * tv.tv_sec); fp = fopen(DICT, "r"); if (! fp) {