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 problem.  The problem still is that
>arc4random()'s range is twice that of it's friends'.

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.

If you insist on a 31-bit random int, try
        (int)(arc4random() & 0x7fffffff)

Peter

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

Reply via email to