[comp.lang.fortran] randu?

haozhou@acsu.buffalo.edu (Hao Zhou) (02/28/91)

I am trying to port some fortran source code from vax/vms to sun/unix.
The source code compiles on unix but doesn't link since randu couldn't
be found. I checked the code and found randu is referred as follows:

	call randu(i1,i2,u)

where i1,i2,and u weren't initialized before the call. I guess this
routine returns a random number in u and i1 and i2 are two seeds.

Obviously this routine is not f77 standard since I couldn't find it in
libF77.a. Instead, I found an equivalent function in libm.a called
rand which belongs to C library.

My question is how do you replace randu with rand? What is the range
of random number given by randu? Hope somebody who is familiar with
the vax version of fortran77 can shed me some light. Thanks.

	Hao

-- 
Internet:haozhou@acsu.buffalo.edu BITNET:haozhou%acsu.buffalo.edu@UBVM.BITNET
UUCP: rutgers!ub!haozhou

KENCB@SLACVM.SLAC.STANFORD.EDU (02/28/91)

In article <62349@eerie.acsu.Buffalo.EDU>, haozhou@acsu.buffalo.edu (Hao Zhou)
says:
>
>I am trying to port some fortran source code from vax/vms to sun/unix.
>The source code compiles on unix but doesn't link since randu couldn't
>be found.

 The subroutine RANDU comes from the CERN (the European high energy physics
 lab) program library called CERNLIB, most likely from the object library
 KERNLIB.OLB.  CERN makes their library available for a variety of platforms,
 including Unix.

>My question is how do you replace randu with rand? What is the range
>of random number given by randu?

 You'll need to check the CERNLIB documentation.  Perhaps one of your
 University colleagues has a copy.  (I'm at home and can't get to my copy
 now, sorry :-(  )
                  -Ken

 Dr. Kenneth H. Fairfield        Internet: Fairfield@Tpc.Slac.Stanford.Edu
 SLAC, P.O.Box 4349, Bin 98      DECnet:   45047::FAIRFIELD (TPC::)
 Stanford, CA   94309            BITNET    Fairfield@SlacTpc
 "These opinions are worth what you paid for 'em...
         ...and are they mine, not SLAC's, Stanford's, nor the DOE's..."

seymour@milton.u.washington.edu (Richard Seymour) (03/01/91)

What about RANDU?
<my comments in "<...>" brackets>
source: vax fortran user's guide, aa-d035c-te, for vms v3.0, fort v3.0)
page D-12  "Compatibility: VAX-11 Fortran and PDP-11  Fortran"

D.3.9  RANDU subroutine
The RANDU subroutine computes a pseudorandom numvber as a single-precision
value uniformly distributed in the range:  0.0 .LE. value .LT. 1.0

<thus from 0 to just-less-than One>

a call to randu has the form:   CALL RANDU (i1,i2,x)
where:  i1, i2 are INTEGER*2 variables or array elements that contain the
  seed for computing the <next> random number
        x is a real variable or array element where the computed random
           number is stored.

notes: 1) the values of i1 and i2 are updated during the computation
   2) the algorithm is:
       if I1=I2=0 set generator base:  x(n+1)=2**16+3
       otherwise:  x(n+1)=(2**16+3)*x(n) mod 2**32
      store generator base x(n=1) in i1,i2

     result is x(n+1) scaled to a real value y(n=1) for 
         0.0 .LE. y(n=1) .LT. 1.0

<p.s. to people copying this routine... the 2**16+3 is MACHINE DEPENDANT!
   other values make better distributions for IBM Pc's etc.>

klassen@sol.UVic.CA (Melvin Klassen) (03/01/91)

haozhou@acsu.buffalo.edu (Hao Zhou) writes:
>I am trying to port some fortran source code from vax/vms to sun/unix.
>The source code compiles on unix but doesn't link since randu couldn't
>be found. I checked the code and found randu is referred as follows:
>
>	call randu(i1,i2,u)
>
>where i1,i2,and u weren't initialized before the call. I guess this
>routine returns a random number in u and i1 and i2 are two seeds.
>
RANDU originated in the IBM SSP (Scientific Subroutine Package)
in the early 1970's.  It has three arguments:
 - IX, which is the "seed" for the (pseudo-) random-number generator,
   (set IX to some positive, odd, number before the very-first CALL),
 - IY, which is returned as the value which the caller should store
   into IX before calling RANDU again,
 - Z, which is returned as a floating-point number *uniformly* (hence
   the U-suffix) distributed in the 0.0 to 1.0 range.

alan@dmsmelb.mel.dms.CSIRO.AU (Alan Miller) (03/01/91)

In article <17397@milton.u.washington.edu> seymour@milton.u.washington.edu
(Richard Seymour) writes:
:What about RANDU?
:
:D.3.9  RANDU subroutine
:The RANDU subroutine computes a pseudorandom numvber as a single-precision
:value uniformly distributed in the range:  0.0 .LE. value .LT. 1.0
:
:a call to randu has the form:   CALL RANDU (i1,i2,x)
:where:  i1, i2 are INTEGER*2 variables or array elements that contain the
:  seed for computing the <next> random number
:        x is a real variable or array element where the computed random
:           number is stored.

RANDU is of course the notorious random number generator (there were others,
but not as bad) highlighted in Marsaglia's famous 'Random numbers fall mainly
in the planes' (Proc. Nat. Acad. Sci. USA, vol.61, 25-, 1968) paper.
I believe that it originated with IBM.   Sorry to hear that it is still alive.

Alan Miller

trh@ukc.ac.uk (T.R.Hopkins) (03/01/91)

In article <17397@milton.u.washington.edu> seymour@milton.u.washington.edu (Richard Seymour) writes:
>What about RANDU?
><my comments in "<...>" brackets>
>source: vax fortran user's guide, aa-d035c-te, for vms v3.0, fort v3.0)
>page D-12  "Compatibility: VAX-11 Fortran and PDP-11  Fortran"
>
>D.3.9  RANDU subroutine
>The RANDU subroutine computes a pseudorandom numvber as a single-precision
>value uniformly distributed in the range:  0.0 .LE. value .LT. 1.0


Is this the dreaded randu described on p104 of Don Knuth's Semi-numerical
Algorithms as "regrettably, the generator that has actually been used on 
such machines (System/370) in most of the world's scientific computing
centres for about a decade; its very name RANDU is enough to bring dismay
into the eyes and stomachs of many computer scientists! .... the generator
fails most 3-dimensional criteria for randomness, and it should never have
been used."

Tim

seymour@milton.u.washington.edu (Richard Seymour) (03/02/91)

haozhou@acsu.buffalo.edu (Hao Zhou) writes:
>>I am trying to port some fortran source code from vax/vms to sun/unix.
>>	call randu(i1,i2,u)
>>where i1,i2,and u weren't initialized before the call. I guess this
>>routine returns a random number in u and i1 and i2 are two seeds.

and i forgot to mention that VMS Fortran predefines all variables to
ZERO, if you don't override it with a data statement
(a consequence of Demand-Zero Virtual memory)

which is why the RANDU routine uses I1=I2=0 as recognition of a initialization.
You can also SET i1 and i2 to zero to replay a random number sequence.
--dick

macq@miguel.llnl.gov (Don MacQueen) (03/02/91)

In article <292@re.ukc.ac.uk>, trh@ukc.ac.uk (T.R.Hopkins) writes:
|> In article <17397@milton.u.washington.edu> seymour@milton.u.washington.edu (Richard Seymour) writes:
|> >What about RANDU?
|> ><my comments in "<...>" brackets>
|> >source: vax fortran user's guide, aa-d035c-te, for vms v3.0, fort v3.0)
|> >page D-12  "Compatibility: VAX-11 Fortran and PDP-11  Fortran"
|> >
|> >D.3.9  RANDU subroutine
|> >The RANDU subroutine computes a pseudorandom numvber as a single-precision
|> >value uniformly distributed in the range:  0.0 .LE. value .LT. 1.0
|> 
|> 
|> Is this the dreaded randu described on p104 of Don Knuth's Semi-numerical
|> Algorithms as "regrettably, the generator that has actually been used on 
|> such machines (System/370) in most of the world's scientific computing
|> centres for about a decade; its very name RANDU is enough to bring dismay
|> into the eyes and stomachs of many computer scientists! .... the generator
|> fails most 3-dimensional criteria for randomness, and it should never have
|> been used."
|> 
|> Tim

-- 
The Macintosh 3-d point cloud spinning program named MacSpin includes a data set created by randu, and they sure aren't random.
--------------------
Don MacQueen
macq@miguel.llnl.gov
--------------------