From owner-freebsd-hackers Tue Feb 18 22:54:26 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 0695637B401 for ; Tue, 18 Feb 2003 22:54:25 -0800 (PST) Received: from cirb503493.alcatel.com.au (c18609.belrs1.nsw.optusnet.com.au [210.49.80.204]) by mx1.FreeBSD.org (Postfix) with ESMTP id 9AC3A43FCB for ; Tue, 18 Feb 2003 22:54:23 -0800 (PST) (envelope-from peterjeremy@optushome.com.au) Received: from cirb503493.alcatel.com.au (localhost.alcatel.com.au [127.0.0.1]) by cirb503493.alcatel.com.au (8.12.5/8.12.5) with ESMTP id h1J6sMLZ066324; Wed, 19 Feb 2003 17:54:22 +1100 (EST) (envelope-from jeremyp@cirb503493.alcatel.com.au) Received: (from jeremyp@localhost) by cirb503493.alcatel.com.au (8.12.6/8.12.5/Submit) id h1J6also066302; Wed, 19 Feb 2003 17:36:47 +1100 (EST) Date: Wed, 19 Feb 2003 17:36:47 +1100 From: Peter Jeremy To: Paul Herman Cc: FreeBSD Hackers Subject: Re: arc4random() range Message-ID: <20030219063646.GB62020@cirb503493.alcatel.com.au> References: <20030219013247.GA10910@x-anthony.com> <20030218180736.L240-100000@mammoth.eat.frenchfries.net> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20030218180736.L240-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 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 majordomo@FreeBSD.org with "unsubscribe freebsd-hackers" in the body of the message