From 4b0ef0922162580d7ac9d4740c3782534ed35660 Mon Sep 17 00:00:00 2001 From: Miroslav Lichvar Date: Mon, 14 Nov 2016 08:43:54 +0100 Subject: [PATCH] sched: add more random bits to timeout scheduling Extend the random value which is included in the calculation of the delay from 16 to 32 bits. This makes scheduling of NTP transmissions random to one microsecond for polling intervals up to 17. --- sched.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/sched.c b/sched.c index a7b8353..0ffbe9e 100644 --- a/sched.c +++ b/sched.c @@ -375,10 +375,10 @@ SCH_AddTimeoutInClass(double min_delay, double separation, double randomness, assert(class < SCH_NumberOfClasses); if (randomness > 0.0) { - uint16_t rnd; + uint32_t rnd; UTI_GetRandomBytes(&rnd, sizeof (rnd)); - r = rnd / (double)0xffff * randomness + 1.0; + r = rnd * (randomness / (uint32_t)-1) + 1.0; min_delay *= r; separation *= r; }