      program ex092
      implicit real*8(a-h,o-z)
      integer*4 iseed
c
      iseed = 123456789
      n = 1000000
      write(*,*) 'n, iseed =?'
      read(*,*) n, iseed
C
      ave=0.0d0
      do i = 1,n
         x = rnd(iseed)
         y = rnd(iseed)
         r = sqrt(x**2 + y**2)
         if(r.le.1) then
            ave = ave + 1.0d0
         endif
      end do
      ave = ave/n
      write(*,*) 'Average (Heikin)   =',ave
      write(*,*) 'Exact              =',atan(1.0d0)  ! pi/4
c
      end
c **********************************************************************
      function rnd(iseed)
c **********************************************************************
      implicit real*8(a-h,o-z)
c...32 bit (=4byte) machine
      integer*4 iseed,il,ic,ih
      il = 843314861
      ic = 453816693
      ih = 2**30
      xmax = 2.0d0**31
c
      iseed = iseed*il + ic
      if(iseed.lt.0) iseed = (iseed + ih) + ih
      rnd = iseed/xmax
c
      end
