Help Files: Fortran77: Random





     HELP                      June 15, 1985                F77/RANDOM



                         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().   While  the
     NAG or IMSL libraries are available or many systems, they are not
     part of the standard distribution; see your system  administrator
     to find out if they are on your 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:

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

     The first call with argument of 1 starts the  sequence  with  the
     same number each time the program is run.  This is useful for de-
     bugging 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:

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

     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:

                   real randsp(100), ggubfs
                   double precision dseed

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

     'dseed' is changed by ggubfs(), so it must be a variable and your
     program  must  not  change it between calls to ggubfs().  The se-
     quence generated depends on the initial value of 'dseed'; it must
     be  between  1.0d0  and  2147483647.0d0 .  To access the IMSL li-
     brary, 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():

                   double precision randdp(100), g05caf

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

     g05caf() uses common blocks /ag05ca/ and /bg05ca/, so  your  pro-
     gram should not changes values in these common blocks.  This gen-
     erates the same sequence each time it is used; to generate a dif-
     ferent 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 se-
     quence using the current time to generate a seed.  To access  the
     NAG library, add '-lnagd' at the end of your f77 command.

     


Comments to decf@euler.berkeley.edu
© 1998 UC Regents