Skip site navigation (1)Skip section navigation (2)
Date:      Wed, 30 Jul 2003 23:20:11 -0700 (PDT)
From:      David Schultz <das@FreeBSD.ORG>
To:        freebsd-bugs@FreeBSD.org
Subject:   Re: bin/54878: incorrect divisor in /usr/bin/jot -r
Message-ID:  <200307310620.h6V6KB9H082957@freefall.freebsd.org>

next in thread | raw e-mail | index | archive | help
The following reply was made to PR bin/54878; it has been noted by GNATS.

From: David Schultz <das@FreeBSD.ORG>
To: David Brinegar <jot.3.brinegar@spamgourmet.com>
Cc: FreeBSD-gnats-submit@FreeBSD.ORG
Subject: Re: bin/54878: incorrect divisor in /usr/bin/jot -r
Date: Wed, 30 Jul 2003 23:15:43 -0700

 On Sat, Jul 26, 2003, David Brinegar wrote:
 >    For example one would expect something like the following:
 > 
 >    > jot -w %d -r 1000 1 4 | sort -n | uniq -c
 >     333 1
 >     333 2
 >     334 3
 > 
 >    Internally, jot is assigning *y to 1,2,3, and very rarely 4:
 > 
 >       [1.0,2.0) => 1
 >       [2.0,3.0) => 2
 >       [3.0,4.0) => 3
 >            4.0  => 4
 [...]
 >    src/usr.bin/jot/jot.c revision 1.24, line 278:
 > 
 >       *y = arc4random() / (double)UINT32_MAX;
 > 
 >    should be:
 > 
 >       *y = arc4random() / (1.0 + (double)UINT32_MAX);
 
 Actually, to be compatible with the non-random behavior, and to
 make the random letter example in the manpage actually work, jot
 needs to treat integers and floating point numbers differently.
 In particular, 'jot -w %d -r 1000 1 4' needs to give integers
 uniformly distrubited over [1,4], whereas 'jot -w %f -r 1000 1 4'
 needs to give floating point numbers uniformly distributed over
 the same range.  As you rightly point out, the integer
 distribution is skewed if you take a number over the floating
 point distribution and round down.
 
 On a related note, jot should be retrofitted to use fmtcheck(3)
 anyway...



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