Skip site navigation (1)Skip section navigation (2)
Date:      Mon, 04 Dec 2000 09:23:48 +1100
From:      Peter Jeremy <peter.jeremy@alcatel.com.au>
To:        hackers@FreeBSD.ORG
Cc:        sheldonh@uunet.co.za, arnold@skeeve.com
Subject:   Re: BSD random for Alpha?
Message-ID:  <20001204092348.A92196@gsmx07.alcatel.com.au>

next in thread | raw e-mail | index | archive | help
On Wed, 22 Nov 2000 15:18:27 +0200, Sheldon Hearn <sheldonh@uunet.co.za> wrote:
>Anyone want to have a look at this?  It's from the GNU awk maintainer.
>- ------- Forwarded Message
>
>From: Aharon Robbins <arnold@skeeve.com>
>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




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