Date: Wed, 19 Feb 2003 09:27:02 -0800 From: Tim Kientzle <kientzle@acm.org> To: Dag-Erling Smorgrav <des@ofug.org> Cc: phk@phk.freebsd.dk, Paul Herman <pherman@frenchfries.net>, Peter Jeremy <peterjeremy@optushome.com.au>, FreeBSD Hackers <hackers@FreeBSD.ORG> Subject: Re: arc4random() range Message-ID: <3E53BE66.4030609@acm.org> References: <86890.1045646060@critter.freebsd.dk> <xzpsmukwqqb.fsf@flood.ping.uio.no>
next in thread | previous in thread | raw e-mail | index | archive | help
Dag-Erling Smorgrav wrote: > phk@phk.freebsd.dk writes: > >>Well, I'm right in principle but wrong in current practice, at >>the very least make it: >> >>#define arc4random31() (arc4random() & RAND_MAX) >> > > or rather > > #define arc4random31() (arc4random() % (RAND_MAX + 1)) > > to avoid relying on RAND_MAX being one less than a power of two. > > DES > Nope. Because RAND_MAX is one less than a power of two, you run into integer overflow problems, which PHK's version avoids. Tim Kientzle To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe freebsd-hackers" in the body of the message
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?3E53BE66.4030609>