From owner-freebsd-hackers Wed Feb 19 1:14:24 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 B134337B401 for ; Wed, 19 Feb 2003 01:14:23 -0800 (PST) Received: from phk.freebsd.dk (phk.freebsd.dk [212.242.86.175]) by mx1.FreeBSD.org (Postfix) with ESMTP id BBE5143F85 for ; Wed, 19 Feb 2003 01:14:22 -0800 (PST) (envelope-from phk@phk.freebsd.dk) Received: from critter.freebsd.dk (critter.freebsd.dk [212.242.86.163]) by phk.freebsd.dk (8.12.6/8.12.6) with ESMTP id h1J9EL6E090211; Wed, 19 Feb 2003 09:14:21 GMT (envelope-from phk@phk.freebsd.dk) Received: from critter.freebsd.dk (localhost [127.0.0.1]) by critter.freebsd.dk (8.12.6/8.12.6) with ESMTP id h1J9EKOx086891; Wed, 19 Feb 2003 10:14:20 +0100 (CET) (envelope-from phk@phk.freebsd.dk) To: Paul Herman Cc: Peter Jeremy , FreeBSD Hackers Subject: Re: arc4random() range From: phk@phk.freebsd.dk In-Reply-To: Your message of "Wed, 19 Feb 2003 00:59:46 PST." <20030219003725.W240-100000@mammoth.eat.frenchfries.net> Date: Wed, 19 Feb 2003 10:14:20 +0100 Message-ID: <86890.1045646060@critter.freebsd.dk> 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 In message <20030219003725.W240-100000@mammoth.eat.frenchfries.net>, Paul Herma n writes: >> >> > EXAMPLES >> > The following produces a drop-in replacement for the traditional >> > random() and rand() functions using arc4random(): >> > #define arc4random31() (arc4random() & 0x7FFFFFFF) >> >> Not good. Only true on 32 bit archs. > >Heh? > >random(3) produces numbers between 0 and RAND_MAX on my alpha. >random(3) produces numbers between 0 and RAND_MAX on my i386. Well, I'm right in principle but wrong in current practice, at the very least make it: #define arc4random31() (arc4random() & RAND_MAX) -- Poul-Henning Kamp | UNIX since Zilog Zeus 3.20 phk@FreeBSD.ORG | TCP/IP since RFC 956 FreeBSD committer | BSD since 4.3-tahoe Never attribute to malice what can adequately be explained by incompetence. To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe freebsd-hackers" in the body of the message