.TI F77/RANDOM "Sep. 4, 1985"
Random Number Generators

You can generate sequences of random numbers using random()
from the f77 system library, or by using procedures in the IMSL or
NAG libraries.
This help file includes examples using random(),
ggubs() from the IMSL library and g05caf() from the NAG library.
ggubs() and g05caf() are recommended over random().
See "help f77 nag" and "help f77 imsl" for information on whether IMSL
and NAG are available on this system.

The functions random(), irandm(), and drandm() in the f77 library
provide sequence of real, integer and double precision random numbers.
To get a sequence of 100 pseudo-random numbers between 0 and 1.0:

.nf
		real x(100)
		   ...
		x(1) = random(1)
		do 10 i=2,100
	10	x(i) = random(0)
.fi

The first call with argument of 1 starts the sequence with the same
number each time the program is run.  This is useful for debugging when
you need to compare two runs.  The later calls with argument of 0
cause the next random number in the sequence to be returned.  If you
want to generate a different sequence each time the program is run,
use:

.nf
		integer time
		real x(100)
		   ...
		x(1) = random(time())
		do 10 i=2,100
	10	x(i) = random(0)
.fi

For details, see "man 3f random".

NAG section G05 and IMSL chapter G contain over 80 subroutines dealing
with generating and testing pseudo-random numbers.  To generate a
sequence of 100 single precision pseudo-random numbers in the interval (0.,1.)
using IMSL's ggubs:

.nf
	      real randsp(100), ggubfs
	      double precision dseed

	      dseed = 123457.d0
	      do 20 i = 1, 100
	20    randsp(i) =  ggubfs( dseed )
.fi

\&'dseed' is changed by ggubfs(), so it must be a variable and your program
must not change it between calls to ggubfs().  The sequence generated depends
on the initial value of 'dseed'; it must be between 1.0d0 and 2147483647.0d0 .
To access the IMSL library, add '-limsld' at the end of your f77 command.

To generate a sequence of 100 double pseudo-random precision numbers
in the interval (0.,1.) using NAG's g05caf():

.nf
	      double precision randdp(100), g05caf

	      do 30 i = 1,100
	30    randdp(i) = g05caf(dummy)
.fi

g05caf() uses common blocks /ag05ca/ and /bg05ca/, so your program
should not changes values in these common blocks.  This generates the
same sequence each time it is used; to generate a different sequence
each time your program is run, begin your program with:

	      call g05ccf

g05ccf should be called before the first call on g05caf() and should be
called only once.  It will initialize the random sequence using the
current time to generate a seed.  To access the NAG library,
add '-lnagd' at the end of your f77 command.
