From ab84eade0a946e094f0852430d47625e38a6a3c5 Mon Sep 17 00:00:00 2001 From: Miroslav Lichvar Date: Fri, 25 Oct 2013 14:45:35 +0200 Subject: [PATCH] Make random() more random between machines. Include also nanoseconds from the current time in the srandom() call. This should significantly decrease the chance of two machines using the same random sequence. Signed-off-by: Miroslav Lichvar --- clock.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/clock.c b/clock.c index 74d5c77..f6bad00 100644 --- a/clock.c +++ b/clock.c @@ -576,12 +576,14 @@ struct clock *clock_create(int phc_index, struct interface *iface, int count, struct clock *c = &the_clock; char phc[32]; struct interface udsif; + struct timespec ts; memset(&udsif, 0, sizeof(udsif)); snprintf(udsif.name, sizeof(udsif.name), "%s", uds_path); udsif.transport = TRANS_UDS; - srandom(time(NULL)); + clock_gettime(CLOCK_REALTIME, &ts); + srandom(ts.tv_sec ^ ts.tv_nsec); if (c->nports) clock_destroy(c);