Re: arc4random() range

2003-02-23 Thread Greg 'groggy' Lehey
On Wednesday, 19 February 2003 at 9:22:18 -0800, Wes Peters wrote: > On Tuesday 18 February 2003 22:36, Peter Jeremy wrote: >> >> I see this as a major advantage of arc4random() - if I want 32-bit >> random numbers I don't have to call random() twice and merge the >> results. I've never understoo

Re: arc4random() range

2003-02-19 Thread Bob Bishop
Hi, At 17:27 19/2/03, Tim Kientzle wrote: Dag-Erling Smorgrav wrote: [EMAIL PROTECTED] 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_M

Re: arc4random() range

2003-02-19 Thread Wes Peters
On Tuesday 18 February 2003 22:36, Peter Jeremy wrote: > > I see this as a major advantage of arc4random() - if I want 32-bit > random numbers I don't have to call random() twice and merge the > results. I've never understood why random() was specified to return > a '0' in the MSB. It probably ha

Re: arc4random() range

2003-02-19 Thread Tim Kientzle
Dag-Erling Smorgrav wrote: [EMAIL PROTECTED] 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 be

Re: arc4random() range

2003-02-19 Thread Dag-Erling Smorgrav
Peter Jeremy <[EMAIL PROTECTED]> writes: > In any case, doesn't the name imply that it's 31-bits... Yes, it's a bad name. DES -- Dag-Erling Smorgrav - [EMAIL PROTECTED] To Unsubscribe: send mail to [EMAIL PROTECTED] with "unsubscribe freebsd-hackers" in the body of the message

Re: arc4random() range

2003-02-19 Thread Dag-Erling Smorgrav
[EMAIL PROTECTED] 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

Re: arc4random() range

2003-02-19 Thread David Schultz
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. > > > > Goo

Re: arc4random() range

2003-02-19 Thread phk
In message <[EMAIL PROTECTED]>, Paul Herma n writes: >> >> > EXAMPLES >> > The following produces a drop-in replacement for the traditional >> > random() and rand() functions using arc4random(): >> > #define arc4random31() (arc4random() & 0x7FFF) >> >> Not good. Only true on 32 bit a

Re: arc4random() range

2003-02-19 Thread Paul Herman
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 repla

Re: arc4random() range

2003-02-19 Thread phk
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 usi

Re: arc4random() range

2003-02-19 Thread Paul Herman
On Wed, 19 Feb 2003, Peter Jeremy wrote: > On Tue, Feb 18, 2003 at 06:22:37PM -0800, Paul Herman wrote: > > > > [...range of arc4random() is twice that of random()...] > > I see this as a major advantage of arc4random() I see this as an advantage, too. It's also produces random numbers with a ver

Re: arc4random() range

2003-02-18 Thread Peter Jeremy
On Tue, Feb 18, 2003 at 06:22:37PM -0800, Paul Herman wrote: >On Tue, 18 Feb 2003, Anthony Schneider wrote: > >> an issue of arc4random return u_int32_t and rand* >> returning int (ie unsigned vs signed)? > >Nope, casting arc4random() to int or casting random() to unsigned >int won't solve the prob

Re: arc4random() range

2003-02-18 Thread Paul Herman
On Tue, 18 Feb 2003, Anthony Schneider wrote: > an issue of arc4random return u_int32_t and rand* > returning int (ie unsigned vs signed)? Nope, casting arc4random() to int or casting random() to unsigned int won't solve the problem. The problem still is that arc4random()'s range is twice that o

Re: arc4random() range

2003-02-18 Thread Anthony Schneider
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

Re: arc4random() range

2003-02-18 Thread Kris Kennaway
On Tue, Feb 18, 2003 at 04:04:57PM -0800, Paul Herman wrote: > 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]: rand() and random() return signed values (i

arc4random() range

2003-02-18 Thread Paul Herman
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; #d