From owner-freebsd-hackers Wed Feb 19 9:37:26 2003 Delivered-To: freebsd-hackers@freebsd.org Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125]) by hub.freebsd.org (Postfix) with ESMTP id 8B78537B401 for ; Wed, 19 Feb 2003 09:37:25 -0800 (PST) Received: from gidgate.gid.co.uk (gid.co.uk [194.32.164.225]) by mx1.FreeBSD.org (Postfix) with ESMTP id 4C70643FA3 for ; Wed, 19 Feb 2003 09:37:24 -0800 (PST) (envelope-from rb@gid.co.uk) Received: (from rb@localhost) by gidgate.gid.co.uk (8.11.6/8.11.6) id h1JHbIc13867; Wed, 19 Feb 2003 17:37:18 GMT (envelope-from rb) Message-Id: <4.3.2.7.2.20030219173629.0213a848@gid.co.uk> X-Sender: rbmail@gid.co.uk X-Mailer: QUALCOMM Windows Eudora Version 4.3.2 Date: Wed, 19 Feb 2003 17:37:17 +0000 To: kientzle@acm.org, Dag-Erling Smorgrav From: Bob Bishop Subject: Re: arc4random() range Cc: phk@phk.freebsd.dk, Paul Herman , Peter Jeremy , FreeBSD Hackers In-Reply-To: <3E53BE66.4030609@acm.org> References: <86890.1045646060@critter.freebsd.dk> Mime-Version: 1.0 Content-Type: text/plain; charset="us-ascii"; format=flowed Sender: owner-freebsd-hackers@FreeBSD.ORG Precedence: bulk List-ID: List-Archive: (Web Archive) List-Help: (List Instructions) List-Subscribe: List-Unsubscribe: X-Loop: FreeBSD.ORG Hi, At 17:27 19/2/03, Tim Kientzle wrote: >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. #define arc4random31() (arc4random() % ((unsigned)RAND_MAX + 1)) -- Bob Bishop +44 (0)118 977 4017 rb@gid.co.uk fax +44 (0)118 989 4254 To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe freebsd-hackers" in the body of the message