From owner-svn-src-head@freebsd.org Sun May 22 03:10:12 2016 Return-Path: Delivered-To: svn-src-head@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id ED116B3B57B; Sun, 22 May 2016 03:10:12 +0000 (UTC) (envelope-from brde@optusnet.com.au) Received: from mail108.syd.optusnet.com.au (mail108.syd.optusnet.com.au [211.29.132.59]) by mx1.freebsd.org (Postfix) with ESMTP id A6A29186D; Sun, 22 May 2016 03:10:12 +0000 (UTC) (envelope-from brde@optusnet.com.au) Received: from c122-106-149-109.carlnfd1.nsw.optusnet.com.au (c122-106-149-109.carlnfd1.nsw.optusnet.com.au [122.106.149.109]) by mail108.syd.optusnet.com.au (Postfix) with ESMTPS id 521241A28E2; Sun, 22 May 2016 13:10:10 +1000 (AEST) Date: Sun, 22 May 2016 13:10:09 +1000 (EST) From: Bruce Evans X-X-Sender: bde@besplex.bde.org To: Andrey Chernov cc: Bruce Evans , Pedro Giffuni , cem@freebsd.org, src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: Re: svn commit: r300377 - head/sys/compat/ndis In-Reply-To: <8bd5428f-6955-72c3-0294-72f7ef936e16@freebsd.org> Message-ID: <20160522124923.I1697@besplex.bde.org> References: <201605211752.u4LHqiHQ031457@repo.freebsd.org> <262938a6-50bd-b6f4-24c9-895b837a368e@FreeBSD.org> <20160522091455.A1014@besplex.bde.org> <8bd5428f-6955-72c3-0294-72f7ef936e16@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.1 cv=EfU1O6SC c=1 sm=1 tr=0 a=R/f3m204ZbWUO/0rwPSMPw==:117 a=L9H7d07YOLsA:10 a=9cW_t1CCXrUA:10 a=s5jvgZ67dGcA:10 a=kj9zAlcOel0A:10 a=8wdhbwkFtMgtjcdClAAA:9 a=CjuIK1q_8ugA:10 X-BeenThere: svn-src-head@freebsd.org X-Mailman-Version: 2.1.22 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: Sun, 22 May 2016 03:10:13 -0000 On Sun, 22 May 2016, Andrey Chernov wrote: > On 22.05.2016 3:06, Bruce Evans wrote: >> ... >> FreeBSD still has the ACM version in libkern, and has a fixed copy >> of that in libc, with the bad old version under an ifdef. >> >> The libc version now adjusts the range from [0, 0x7fffffff] to >> 0, 0x7ffffffd] and reduces RAND_MAX by 2 to match. The claimed uniformity >> for the larger range is very wrong, since the ACM algorithm can only >> produce numbers in the range [1(or is it 0?), 0x7ffffffe] starting from a >> seed in the range [1, 0x7ffffffe(or is it 1 higher?)]. There are problems >> at both extremities, and it isn't clear if the new or old adjustments to >> avoid them preserve uniformity. It is clear that the range was at least >> 1 too high, since the ACM algorithm does a modulo by 0x7fffffff. > > libc version does range adjustment for better uniformity only for > rand(3), not for random(3). There is no RAND_MAX constant in the > random(3) API. POSIX require that random(3) should stay in [0, 2^31-1]. The one in the kernel is random(9) being used to implement rand(9). This doesn't have to conform to POSIX or be very good. random(9) is actually really rand(9) under a different name. It uses a LCG with a small period, but random(3) is specified to be the BSD one, with wording too similar to that in the FreeBSD man page -- it must use a nonlinear method with a default period of 16 times larger than 2**31-1, and must give a period larger than 2**69 with a state table size of 256. The default should have been changed to much more than 16 times larger long before POSIX standardized the 1980's default. Bruce