Thus spake Paul Herman <[EMAIL PROTECTED]>:
> On Wed, 19 Feb 2003 [EMAIL PROTECTED] wrote:
> 
> > In message <[EMAIL PROTECTED]>, Paul Herma
> > n writes:
> >
> > >  arc4random() returns random numbers in the range of 0 to
> > >  (2**32)-1, and therefore has twice the range of RAND_MAX.
> >
> > Good.
> >
> > >  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.
> (arc4random() & 0x7FFFFFFF) produces numbers between 0 and RAND_MAX on my alpha.
> (arc4random() & 0x7FFFFFFF) produces numbers between 0 and RAND_MAX on my i386.

Your code should work fine, although it assumes RAND_MAX is
2^31-1, rather than using the symbolic constant.  But I think if
people were really interested in using arc4random() as a drop-in
replacement for random(), they would have already written a libc
function to mimic random().  Just documenting the range of
arc4random() should be sufficient.

To Unsubscribe: send mail to [EMAIL PROTECTED]
with "unsubscribe freebsd-hackers" in the body of the message

Reply via email to