      implicit none
!
      integer, parameter :: trials = 200, width = 30
      double precision :: pi, x, y
      integer :: in, out
      integer :: i, j, k, ix, iy, n
      integer, dimension(8) :: values
      character (width*2) :: dots(width)
!
      call date_and_time(VALUES=values)
      call srand(values(8))
!
      dots(width)(1:1) = '+'
      dots(width - 1)(1:1) = '|'
      do j = 2, width * 2
        dots(width)(j:j) = '-'
        dots(width - 1)(j:j) = ' '
      end do
!
      do i = 1, width - 2
        dots(i)(1:1) = '|'
        dots(i)(2:2) = ' '
        do j = 3, width * 2
          dots(i)(j:j) = ' '
        end do
      end do
!
      in = 0
      out = 0
!
      do i = 1, trials
        x = rand()
        y = rand()
        ix = int(x * (width - 1) + 1)
        iy = int(y * (width - 1) + 1)
!
        if (x * x + y * y < 1.0d+0) then
          in = in + 1
          dots(width - iy)(ix * 2 + 1:ix * 2 + 2) = '* '
        else
          out = out + 1
          dots(width - iy)(ix * 2 + 1:ix * 2 + 2) = '. '
        end if
!
        if (i < 30 .or. mod(i, 20) == 0 .or. i == trials) then
          print *
          print *
          do j = 1, width
            print *, (' ', dots(j)(k:k),k=1,2*width)
          end do
          print '(a,i3,a,f8.4,a,f8.4,a)',
     $      ' point[', i, ']: ( ', x, ', ', y, ' )'
          print '(a,i3,a,i3)', ' probability : ', in, '/', in + out
          print *, ' pi = ', dble(in) / dble(in + out) * 4.0d+0
!
          if (i < 3) then
            call sleep(1)
          else if (i < 8) then
            call sleep(1)
          else
            call sleep(1)
          end if
        end if
      end do
!
      end
