routed(8): Use arc4random_uniform instead of arc4random.

Use arc4random_uniform() when the desired random number upper bound
is not a power of two.

While here, we don't need srandom() and friends anymore.

Obtained from:	OpenBSD (CVS rev. 1.20)
This commit is contained in:
Pedro F. Giffuni 2016-05-15 06:06:22 +00:00
parent 73ffff5f64
commit bdfd68dca7
Notes: svn2git 2020-12-20 02:59:44 +00:00
svn path=/head/; revision=299845

View File

@ -303,11 +303,6 @@ main(int argc,
pidfile(0);
#endif
mypid = getpid();
#ifdef __FreeBSD__
srandomdev();
#else
srandom((int)(clk.tv_sec ^ clk.tv_usec ^ mypid));
#endif
/* prepare socket connected to the kernel.
*/
@ -826,8 +821,8 @@ intvl_random(struct timeval *tp, /* put value here */
{
tp->tv_sec = (time_t)(hi == lo
? lo
: (lo + arc4random() % ((hi - lo))));
tp->tv_usec = arc4random() % 1000000;
: (lo + arc4random_uniform(1 + hi - lo)));
tp->tv_usec = arc4random_uniform(1000000);
}