      program ex094
      implicit real*8(a-h,o-z)
      integer*4 iseed
C
      iseed = 123456789
      m = 100000
C
      ave = 0.0d0
      do i = 1,m
         k = 0
         n = 0
 1000    continue
         n = n + 1
         x = rnd(iseed)
         if(x.lt.1.0d0/6.0d0) then
            k = k + 1
         endif
         if(k.ne.5) goto 1000
         ave = ave + n
      end do

      write(*,*) 'Average =',ave/m
c
 100  format(3f10.4)
      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
