From owner-freebsd-hackers Tue Feb 18 17:32:19 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 EB3FB37B401 for ; Tue, 18 Feb 2003 17:32:17 -0800 (PST) Received: from gunjin.wccnet.org (gunjin.wccnet.org [198.111.176.99]) by mx1.FreeBSD.org (Postfix) with ESMTP id C3A4343F85 for ; Tue, 18 Feb 2003 17:32:16 -0800 (PST) (envelope-from anthony@gunjin.wccnet.org) Received: from gunjin.wccnet.org (localhost.rexroof.com [127.0.0.1]) by gunjin.wccnet.org (8.12.3/8.12.2) with ESMTP id h1J1WmU9011485; Tue, 18 Feb 2003 20:32:48 -0500 (EST) Received: (from anthony@localhost) by gunjin.wccnet.org (8.12.3/8.12.3/Submit) id h1J1Wm11011483; Tue, 18 Feb 2003 20:32:48 -0500 (EST) Date: Tue, 18 Feb 2003 20:32:48 -0500 From: Anthony Schneider To: Paul Herman Cc: FreeBSD Hackers Subject: Re: arc4random() range Message-ID: <20030219013247.GA10910@x-anthony.com> References: <20030218153651.A240-100000@mammoth.eat.frenchfries.net> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20030218153651.A240-100000@mammoth.eat.frenchfries.net> User-Agent: Mutt/1.4i 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 an issue of arc4random return u_int32_t and rand* returning int (ie unsigned vs signed)? -Anthony. On Tue, Feb 18, 2003 at 04:04:57PM -0800, Paul Herman wrote: > Hi, > > ...a potential quick commit for someone. :-) > > What's the concesus that arc4random() should be a drop-in > replacement for rand()/random()? Consider the following that > caclulates the average of a bunch of random numbers on [0.0, 1.0]: > > bash$ cat rand.c > #include > > int i; > double avg; > > #define ITERATIONS 1000000 > #define FIND_AVG(func) do { \ > for (i=0, avg = 0.0; i avg += (double)func()/(double)RAND_MAX; \ > printf("avg:\t%f\n", avg/ITERATIONS); \ > } while (0) > > int main() { > FIND_AVG(rand); > FIND_AVG(random); > FIND_AVG(arc4random); > return 0; > } > bash$ cc rand.c && ./a.out > avg: 0.500404 > avg: 0.500007 > avg: 1.001370 <--- !!!!!! > bash$ uname -r > 4.7-STABLE > bash$ > > Is is just understood that arc4random() doesn't obey RAND_MAX, or > should it? Whatever the answer is, perhaps the manpage should > state what the range is like the manpages for rand(3) and random(3) > do. > > -Paul. > > > To Unsubscribe: send mail to majordomo@FreeBSD.org > with "unsubscribe freebsd-hackers" in the body of the message To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe freebsd-hackers" in the body of the message