From:	CSBVAX::CSBVAX::MRGATE::"SMTP::CRVAX.SRI.COM::RELAY-INFO-VAX"  6-MAR-1989 19:27
To:	MRGATE::"ARISIA::EVERHART"
Subj:		Random number generators


Received: From KL.SRI.COM by CRVAX.SRI.COM with TCP; Mon,  6 MAR 89 10:38:01 PDT
Received: from NSS.Cs.Ucl.AC.UK by KL.SRI.COM with TCP; Mon, 6 Mar 89 10:29:36 PST
Received: from ncdlab.ulcc.ac.uk by NSS.Cs.Ucl.AC.UK   via Janet with NIFTP
           id aa01497; 6 Mar 89 17:43 GMT
Date:		 6-MAR-1989 18:14:49 GMT
From:		KEVIN%ncdlab.ulcc.ac.uk@NSS.Cs.Ucl.AC.UK
To:		info-vax <@NSS.Cs.Ucl.AC.UK:info-vax@kl.sri.com>
Subject:	Random number generators
Sender:  "JANET K.Ashley@Uk.Ac.Ulcc.Ncdlab" (Kevin Ashley, ULCC Networks + Comms) <KEVIN%ncdlab.ulcc.ac.uk@NSS.Cs.Ucl.AC.UK>
Postal-Address:	ULCC, 20 Guilford St, LONDON WC1N 1DZ
Telephone:	[+44] (01)-405-8400

The following random number generator is from the Journal
of the Royal Statistical Society, Series C (Applied statistics.)
The method is due to I.D.Hill and B.A.Wichmann.
It is intended to be portable between 16 bit,32 bit and other-bit machines
(it was originally tested on 16-bit PDP11s and 36-bit DECsystem 20's).

It's relatively fast, and much more reliable than any system-supplied RAN
function that I've seen.

      FUNCTION RANDOM(L)
C
C        ALGORITHM AS 183  APPL. STATIST. (1982) VOL.31, NO.2
C
C        RETURNS A PSEUDO-RANDOM NUMBER RECTANGULARLY DISTRIBUTED
C        BETWEEN 0 AND 1.
C
C        IX, IY AND IZ SHOULD BE SET TO INTEGER VALUES BETWEEN
C        1 AND 30000 BEFORE FIRST ENTRY
C
C        INTEGER ARITHMETIC UP TO 30323 IS REQUIRED
C
      COMMON /RAND/ IX, IY, IZ
      IX = 171 * MOD(IX, 177) - 2  * (IX / 177)
      IY = 172 * MOD(IY, 176) - 35 * (IY / 176)
      IZ = 170 * MOD(IZ, 178) - 63 * (IZ / 178)
C
      IF (IX .LT. 0) IX = IX + 30269
      IF (IY .LT. 0) IY = IY + 30307
      IF (IZ .LT. 0) IZ = IZ + 30323
C
C        IF INTEGER ARITHMETIC UP TO 5212632 IS AVAILABLE,
C        THE PRECEDING 6 STATEMENTS MAY BE REPLACED BY
C
C        IX = MOD(171 * IX, 30269)
C        IY = MOD(172 * IY, 30307)
C        IZ = MOD(170 * IZ, 30323)
C
C        ON SOME MACHINES, THIS MAY SLIGHTLY INCREASE
C        THE SPEED. THE RESULTS WILL BE IDENTICAL.
C
      RANDOM = AMOD(FLOAT(IX) / 30269.0 + FLOAT(IY) / 30307.0 +
     *              FLOAT(IZ) / 30323.0, 1.0)
      RETURN
      END


