From owner-freebsd-hackers Sun Dec 3 14:24:36 2000 From owner-freebsd-hackers@FreeBSD.ORG Sun Dec 3 14:24:33 2000 Return-Path: Delivered-To: freebsd-hackers@freebsd.org Received: from netau1.alcanet.com.au (ntp.alcanet.com.au [203.62.196.27]) by hub.freebsd.org (Postfix) with ESMTP id 0781E37B400 for ; Sun, 3 Dec 2000 14:24:29 -0800 (PST) Received: from mfg1.cim.alcatel.com.au (mfg1.cim.alcatel.com.au [139.188.23.1]) by netau1.alcanet.com.au (8.9.3 (PHNE_18979)/8.9.3) with ESMTP id JAA03679; Mon, 4 Dec 2000 09:23:52 +1100 (EDT) Received: from gsmx07.alcatel.com.au by cim.alcatel.com.au (PMDF V5.2-32 #37640) with ESMTP id <01JXAV2TYKLC902V69@cim.alcatel.com.au>; Mon, 4 Dec 2000 09:23:50 +1100 Received: (from jeremyp@localhost) by gsmx07.alcatel.com.au (8.11.0/8.11.0) id eB3MNn592356; Mon, 04 Dec 2000 09:23:49 +1100 (EST envelope-from jeremyp) Content-return: prohibited Date: Mon, 04 Dec 2000 09:23:48 +1100 From: Peter Jeremy Subject: Re: BSD random for Alpha? To: hackers@FreeBSD.ORG Cc: sheldonh@uunet.co.za, arnold@skeeve.com Message-id: <20001204092348.A92196@gsmx07.alcatel.com.au> MIME-version: 1.0 Content-type: text/plain; charset=us-ascii Content-disposition: inline User-Agent: Mutt/1.2.5i Sender: jeremyp@gsmx07.alcatel.com.au Sender: owner-freebsd-hackers@FreeBSD.ORG Precedence: bulk X-Loop: FreeBSD.ORG On Wed, 22 Nov 2000 15:18:27 +0200, Sheldon Hearn wrote: >Anyone want to have a look at this? It's from the GNU awk maintainer. >- ------- Forwarded Message > >From: Aharon Robbins >Date: Wed, 22 Nov 2000 11:59:10 +0200 >Message-ID: <974887150.75c0d57f@skeeve.com> >To: sheldonh@uunet.co.za >Subject: BSD random for Alpha? >Cc: bostic@bostic.com, michal@phys.ualberta.ca > >Hi. I've switched to the new random.c you sent me for gawk. My >Linux/Alpha Guru reports that the code in it assumes that sizeof(long) >is always 4, and one particular test doesn't "look" very random on >the Alpha. > >My question is, is there a better version of random that can deal >with both 32 and 64 bit systems in the same source code? Would >the NetBSD people maybe have such a thing? Try a Fibonacci-sequence random number generator (they're mentioned in Knuth). The general form is: X[n] = (X[n-j] + X[n-k]) mod m where m is any power of 2 (implying that the same generator can be used with any word-size) and k-j > 15. Knuth includes a table of `good' values for j and k. The period is >> 2^k. Off the top of my head (24,55) is a good pair. (The only downside according to Knuth is a lack of theory to explain the behaviour, though this may have been rectified in the 25(?) years since it was written). The normal implementation is an array of size k with two indices representing [n-j] and [n-k], which wrap as appropriate. The initial values should not be all even. Peter To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe freebsd-hackers" in the body of the message