From owner-freebsd-hackers@FreeBSD.ORG Thu Aug 28 14:22:51 2014 Return-Path: Delivered-To: freebsd-hackers@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) (using TLSv1 with cipher ADH-AES256-SHA (256/256 bits)) (No client certificate requested) by hub.freebsd.org (Postfix) with ESMTPS id D6584C7 for ; Thu, 28 Aug 2014 14:22:51 +0000 (UTC) Received: from nimbus.fccf.net (nimbus.fccf.net [77.77.144.35]) by mx1.freebsd.org (Postfix) with ESMTP id 734961C9B for ; Thu, 28 Aug 2014 14:22:50 +0000 (UTC) Received: from straylight.m.ringlet.net (unknown [78.90.13.150]) by nimbus.fccf.net (Postfix) with ESMTPSA id AC9FF4AB for ; Thu, 28 Aug 2014 17:22:49 +0300 (EEST) Received: from roam (uid 1000) (envelope-from roam@ringlet.net) id 254004f by straylight.m.ringlet.net (DragonFly Mail Agent v0.9); Thu, 28 Aug 2014 17:21:47 +0300 Date: Thu, 28 Aug 2014 17:21:47 +0300 From: Peter Pentchev To: Chenguang Li Subject: Re: On changing rand(3) to random(3) in awk(1) Message-ID: <20140828142147.GA2200@straylight.m.ringlet.net> Mail-Followup-To: Chenguang Li , Vitaly Magerya , freebsd-hackers@freebsd.org References: <53FEFBB8.5040305@gmail.com> <20140828131526.GA2385@straylight.m.ringlet.net> <5C40F611-22EB-49E4-8925-37922E771C0F@gmail.com> <20140828133846.GB2385@straylight.m.ringlet.net> MIME-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha256; protocol="application/pgp-signature"; boundary="azLHFNyN32YCQGCU" Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.5.23 (2014-03-12) Cc: freebsd-hackers@freebsd.org, Vitaly Magerya X-BeenThere: freebsd-hackers@freebsd.org X-Mailman-Version: 2.1.18-1 Precedence: list List-Id: Technical Discussions relating to FreeBSD List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 28 Aug 2014 14:22:52 -0000 --azLHFNyN32YCQGCU Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Content-Transfer-Encoding: quoted-printable On Thu, Aug 28, 2014 at 10:17:55PM +0800, Chenguang Li wrote: > -----BEGIN PGP SIGNED MESSAGE----- > Hash: SHA512 >=20 > Chenguang Li wrote: >=20 > > Peter Pentchev wrote: > >=20 > >>> ... ... > >>> [omitted] > >> > >> Right, but you've hard-coded RANDOM_MAX to 2^32-1. I don't think this > >> is correct; I do believe that you should use LONG_MAX for this value. > >> Of course, #define RANDOM_MAX LONG_MAX could be fine for this purpose > >> here, but the point is to use LONG_MAX instead of 2^32-1. > >=20 > > I got your point, updated again. :) >=20 > Wait a minute, isn't LONG_MAX architecture-dependent? It's 92233720368547= 75807=20 > on my 64-bit FreeBSD box. The range of generated random numbers is explic= itly=20 > documented. So I am afraid I should hard-code 2^32-1 in the file. Oof. Sorry. My bad. I missed the *second* sentence of the random(3) manual page, didn't I. Specifically looked it over, looked for limits, checked the bottom for various sections that may document constants and stuff... and missed the second sentence. Of course you're right, it's documented as 2^32-1. Though now I wonder whether stdlib.h shouldn't provide some kind of RANDOM_MAX constant for this purpose, instead of programs having to do their own hardcoding. G'luck, Peter --=20 Peter Pentchev roam@ringlet.net roam@FreeBSD.org p.penchev@storpool.com PGP key: http://people.FreeBSD.org/~roam/roam.key.asc Key fingerprint 2EE7 A7A5 17FC 124C F115 C354 651E EFB0 2527 DF13 --azLHFNyN32YCQGCU Content-Type: application/pgp-signature; name="signature.asc" Content-Description: Digital signature -----BEGIN PGP SIGNATURE----- Version: GnuPG v1 iQIcBAEBCAAGBQJT/zr3AAoJEGUe77AlJ98TROsP/0rM1GD5O7ILMKAWTeBh1vAi j0/L8m+tQHg6XvJ2af08xlTEpkUq21lszOmYw0yLtSOolFajZEaMjSOQfFSQ5MHy oB+dcObVQf1kJ/Elj/HgpOQ1pI1Q4WvVT5jZbKyr6puLeY7EZfcNGJkV9hrtjRA/ gRELgrC0PHhx1gGHFoJHId30ep4mjWxs6puRoB5ESldkHwCaYlfRNdNdw3vf6Jxp B9b7DiaskAQHo//4egy1niP7sXUfPGS8oik3Xw1TP8f90Y7QGdw3BvgZf7Va63XH z7nJMusYHby6E1y0K83o/l9gMybu91HOlTBZ2km/aJgdRuRaj6hsR+h5bcdJiNXV DmWhaqqyL4Ows1OZwEuxUH4CYX1YzlUo2eraPHwyOsJ+WKX1lGkcgfZT6YtEjhPs ycaftfm1lciM4ha1bUOPAelS81bw3iwx3AYDNh1Q86VhQmH8URisGdIXgDpGHZtK XfVyuAOJSBL8zjUPR73T4fT2KGNo2n7oL1xXUF0htuBRG8okOOvYf3F+HEtfU+8I ZJGzxztrtzAl9OFDF755HYnkfLacQsZXPlUAJpG6BMjLtxpndnOIHrBwwQJYGu+8 WMrDjYo4Y3HlHGHJlKtLWndYodV5wlOyPqDGN1ZU1B/XsAZJqsBN7kOIpqVoBcvk AIjfNmsAI814/CpnjFTp =vBxV -----END PGP SIGNATURE----- --azLHFNyN32YCQGCU--