From owner-freebsd-bugs@FreeBSD.ORG Wed Jul 30 23:20:14 2003 Return-Path: Delivered-To: freebsd-bugs@hub.freebsd.org Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125]) by hub.freebsd.org (Postfix) with ESMTP id AB04937B414 for ; Wed, 30 Jul 2003 23:20:13 -0700 (PDT) Received: from freefall.freebsd.org (freefall.freebsd.org [216.136.204.21]) by mx1.FreeBSD.org (Postfix) with ESMTP id D262C43FD7 for ; Wed, 30 Jul 2003 23:20:11 -0700 (PDT) (envelope-from gnats@FreeBSD.org) Received: from freefall.freebsd.org (gnats@localhost [127.0.0.1]) by freefall.freebsd.org (8.12.9/8.12.9) with ESMTP id h6V6KBUp082958 for ; Wed, 30 Jul 2003 23:20:11 -0700 (PDT) (envelope-from gnats@freefall.freebsd.org) Received: (from gnats@localhost) by freefall.freebsd.org (8.12.9/8.12.9/Submit) id h6V6KB9H082957; Wed, 30 Jul 2003 23:20:11 -0700 (PDT) Date: Wed, 30 Jul 2003 23:20:11 -0700 (PDT) Message-Id: <200307310620.h6V6KB9H082957@freefall.freebsd.org> To: freebsd-bugs@FreeBSD.org From: David Schultz Subject: Re: bin/54878: incorrect divisor in /usr/bin/jot -r X-BeenThere: freebsd-bugs@freebsd.org X-Mailman-Version: 2.1.1 Precedence: list Reply-To: David Schultz List-Id: Bug reports List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 31 Jul 2003 06:20:14 -0000 The following reply was made to PR bin/54878; it has been noted by GNATS. From: David Schultz To: David Brinegar 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...