Skip site navigation (1)Skip section navigation (2)
Date:      Thu, 28 Aug 2014 17:21:47 +0300
From:      Peter Pentchev <roam@ringlet.net>
To:        Chenguang Li <horus.li@gmail.com>
Cc:        freebsd-hackers@freebsd.org, Vitaly Magerya <vmagerya@gmail.com>
Subject:   Re: On changing rand(3) to random(3) in awk(1)
Message-ID:  <20140828142147.GA2200@straylight.m.ringlet.net>
In-Reply-To: <B6FE2E90-A51B-4ABF-97E2-29881215F95F@gmail.com>
References:  <F70B9462-0898-47EF-AF83-47509F21F84E@gmail.com> <53FEFBB8.5040305@gmail.com> <20140828131526.GA2385@straylight.m.ringlet.net> <5C40F611-22EB-49E4-8925-37922E771C0F@gmail.com> <20140828133846.GB2385@straylight.m.ringlet.net> <E02AE8AA-0974-42C6-AC83-C257DAFE329A@gmail.com> <B6FE2E90-A51B-4ABF-97E2-29881215F95F@gmail.com>

next in thread | previous in thread | raw e-mail | index | archive | help

--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 <horus.li@gmail.com> wrote:
>=20
> > Peter Pentchev <roam@ringlet.net> 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--



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20140828142147.GA2200>