[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Bug#695285: /etc/cron.daily/apt backup RNG is very wasteful



> Thanks, I fixed this now in my bzr tree and it will be part of the
> next upload.

Er, assuming that's revision 2269:
http://anonscm.debian.org/loggerhead/apt/debian-sid/revision/2269/debian/apt.cron.daily

You don't need the final "cut -c1-5".  It is true that cksum returns an
unsigned 32-bit number, and some shells only do 32-bit signed math, but
they simply convert the number to negative.

You either mask off the sign bit with
RANDOM=$(($(dd if=/dev/urandom bs=2 count=1 2> /dev/null | cksum | cut -d' ' -f1) % 0x7fffffff))

Or, of you want to emulate the range of Bash $RANDOM exactly:
RANDOM=$(($(dd if=/dev/urandom bs=2 count=1 2> /dev/null | cksum | cut -d' ' -f1) % 0x7fff))

The "od -d -N2 -An" solution works with a recent enough od.
I was looking to see how old that can be.  The uppercase option flags
are not in 7th edition, but are in POSIX.1 as of 2001:
http://www.unix.com/man-page/posix/0/od/
It also appears to be in xpg4:
http://docs.oracle.com/cd/E19963-01/html/821-1461/od-1.html
And in SunOD 5.8 (2000):
http://www.manpages.info/sunos/od.1.html
GNU textutils 2.0 (1999):
http://sunsite.ualberta.ca/Documentation/Gnu/textutils-2.0/man/od.1.html

Apparently the spec was in POSIX.1 as of 1992, alyhough not NetBSD
as of 2000:
http://gnats.netbsd.org/11204
It was added to NetBSD in 2008:
http://cvsweb.netbsd.org/bsdweb.cgi/src/usr.bin/hexdump/od.1?rev=1.23&content-type=text/x-cvsweb-markup&f=H&only_with_tag=MAIN


Reply to: