On changing rand(3) to random(3) in awk(1)

Peter Pentchev roam at ringlet.net
Thu Aug 28 14:22:52 UTC 2014


On Thu, Aug 28, 2014 at 10:17:55PM +0800, Chenguang Li wrote:
> -----BEGIN PGP SIGNED MESSAGE-----
> Hash: SHA512
> 
> Chenguang Li <horus.li at gmail.com> wrote:
> 
> > Peter Pentchev <roam at ringlet.net> wrote:
> > 
> >>> ... ...
> >>> [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.
> > 
> > I got your point, updated again. :)
> 
> Wait a minute, isn't LONG_MAX architecture-dependent? It's 9223372036854775807 
> on my 64-bit FreeBSD box. The range of generated random numbers is explicitly 
> 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

-- 
Peter Pentchev  roam at ringlet.net roam at FreeBSD.org p.penchev at storpool.com
PGP key:        http://people.FreeBSD.org/~roam/roam.key.asc
Key fingerprint 2EE7 A7A5 17FC 124C F115  C354 651E EFB0 2527 DF13
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 819 bytes
Desc: Digital signature
URL: <http://lists.freebsd.org/pipermail/freebsd-hackers/attachments/20140828/a8b5f71a/attachment.sig>


More information about the freebsd-hackers mailing list