Date: Tue, 18 Feb 2003 20:32:48 -0500 From: Anthony Schneider <anthony@x-anthony.com> To: Paul Herman <pherman@frenchfries.net> Cc: FreeBSD Hackers <hackers@FreeBSD.ORG> Subject: Re: arc4random() range Message-ID: <20030219013247.GA10910@x-anthony.com> In-Reply-To: <20030218153651.A240-100000@mammoth.eat.frenchfries.net> References: <20030218153651.A240-100000@mammoth.eat.frenchfries.net>
next in thread | previous in thread | raw e-mail | index | archive | help
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 <stdlib.h> > > int i; > double avg; > > #define ITERATIONS 1000000 > #define FIND_AVG(func) do { \ > for (i=0, avg = 0.0; i<ITERATIONS; 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
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20030219013247.GA10910>