CXML

ranl 


FORMAT

  RANL (s1, s2, v, n)

Arguments

  s1                  integer*4
                      On entry, s1>=1, the first part of the two-integer
                      seed.
                      On exit, s1 is changed according to n steps of the
                      L'Ecuyer method.

  s2                  integer*4
                      On entry, s2>=1 the second part of the two-integer
                      seed.
                      On exit, s2 is changed according to n steps of the
                      L'Ecuyer method.

  v                   real*4
                      On entry, a one dimensional vector of n elements. v can
                      be a scalar variable if n=1.
                      On exit, contains n pseudorandom uniform[0,1] random
                      numbers generated according to the L'Ecuyer algorithm.

  n                   integer*4
                      On entry, a positive integer specifying the number of
                      random numbers to store in v(1),...,v(n).
                      On exit, unchanged.

Description

  The RANL routine returns a vector of uniform[0,1] random numbers.  After
  you give arguments s1 and s2 initial values, you need not change these,
  except to restart the sequence or to skip to a new subsequence.

  For parallel applications using the RANL routine, CXML provides two
  auxiliary, input programs.  Refer to the descriptions of RANL_SKIP64 and
  RANL_SKIP2.

  The following example computes the volume of a 10-dimensional sphere, using
  a Monte Carlo technique.

  See also the example for RANL_SKIP2.

Example

   c    Monte Carlo Method
        integer n,ndim,m
        parameter ( m = 10 )
        integer*4 s1,s2,i,k
        real*4 pt(m),vol,sum,r,vol_all
        print*,'nr. pts to use: '
        read*,n
        print*,' n= ',n
        print*,'       vol(10-d sphere)    vol(10-d cube) '
        sum=0.0
        s1=12345
        s2=67890
        do k=1,n
           call ranl(s1,s2,pt ,m)
            r=0.0
            do i=1,m
            r=r+pt(i)*pt(i)
            end do
        if(r.le.1.0)sum=sum+1.0
        end do
        vol = sum/n
        vol_all = 2**m*vol
        write(6,900)vol_all,2.0**m
   900  format(1x,2x,f14.2,4x,f14.0)
        end

CXML Home Page

Index of CXML Routines