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 <mlichvar@redhat.com>
This commit is contained in:
parent
23d31d090e
commit
ab84eade0a
4
clock.c
4
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);
|
||||
|
Loading…
x
Reference in New Issue
Block a user