From owner-svn-src-head@FreeBSD.ORG Wed Jul 3 04:44:25 2013 Return-Path: Delivered-To: svn-src-head@FreeBSD.org Received: from mx1.freebsd.org (mx1.freebsd.org [8.8.178.115]) by hub.freebsd.org (Postfix) with ESMTP id 46E89E32; Wed, 3 Jul 2013 04:44:25 +0000 (UTC) (envelope-from brde@optusnet.com.au) Received: from mail104.syd.optusnet.com.au (mail104.syd.optusnet.com.au [211.29.132.246]) by mx1.freebsd.org (Postfix) with ESMTP id F03CF1B7D; Wed, 3 Jul 2013 04:44:24 +0000 (UTC) Received: from c122-106-156-23.carlnfd1.nsw.optusnet.com.au (c122-106-156-23.carlnfd1.nsw.optusnet.com.au [122.106.156.23]) by mail104.syd.optusnet.com.au (Postfix) with ESMTPS id 6F2424215B7; Wed, 3 Jul 2013 14:44:23 +1000 (EST) Date: Wed, 3 Jul 2013 14:43:56 +1000 (EST) From: Bruce Evans X-X-Sender: bde@besplex.bde.org To: Andrey Chernov Subject: Re: RAND_MAX broken In-Reply-To: <51D33552.1030208@freebsd.org> Message-ID: <20130703144126.L1498@besplex.bde.org> References: <201307012143.r61Lhemi067176@svn.freebsd.org> <20130702130818.V865@besplex.bde.org> <20130702165642.X1571@besplex.bde.org> <51D2F571.8050108@freebsd.org> <20130703020550.E8632@besplex.bde.org> <51D33552.1030208@freebsd.org> MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII; format=flowed X-Optus-CM-Score: 0 X-Optus-CM-Analysis: v=2.0 cv=eqSHVfVX c=1 sm=1 a=kj9zAlcOel0A:10 a=PO7r1zJSAAAA:8 a=JzwRw_2MAAAA:8 a=lqUz0ovpAEAA:10 a=uji_oyvObONoAZy2nP4A:9 a=CjuIK1q_8ugA:10 a=ebeQFi2P/qHVC0Yw9JDJ4g==:117 Cc: svn-src-head@FreeBSD.org, svn-src-all@FreeBSD.org, "Pedro F. Giffuni" , src-committers@FreeBSD.org, Bruce Evans X-BeenThere: svn-src-head@freebsd.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: SVN commit messages for the src tree for head/-current List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 03 Jul 2013 04:44:25 -0000 On Wed, 3 Jul 2013, Andrey Chernov wrote: > On 02.07.2013 20:33, Bruce Evans wrote: >> I checked the values returned by rand(). The ACM part works as >> intended, so it never returns RAND_MAX. It also never returns 0. So >> the distribution of values in the documented range [0, RAND_MAX] is >> very non-uniform. It is uniform in [1, RAND_MAX - 1]. To use this >> algorithm for rand(), 1 should have been subtracted, giving a range >> of [0, 0x7ffffffe]. > > Do you mean [0, 0x7ffffffd] (assuming 1 subtracted)? Yes. > See attached patch. > I don't see compatibility problems at least from POSIX specs point of > view - they don't say something specific about RAND_MAX. I like the patch. It is binary compatibility problems and maybe applications assuming that (RAND_MAX + 1) is 0x80000000 so as to do magic bit operations with it that may be problems. Bruce