From 01865c491f871d5470013a28347c3e8733aab2ea Mon Sep 17 00:00:00 2001 From: Colin Patrick McCabe Date: Sat, 13 Mar 2010 07:56:34 -0800 Subject: [PATCH] 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. --- random-word.c | 7 +++++-- 1 files changed, 5 insertions(+), 2 deletions(-) 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) { -- 1.6.6.rc1.39.g9a42