      subroutine ex08
      implicit none
      integer iy,i,j,imax,N,  Ny
      real*8 r,dx,X(1001),Box(1000),BoxP(1000)
      real*8 s,dy,Y(1001),Boy(1000),BoyP(1000), Ymin, Ymax
      data iy,imax,N, Box/1234567,1000000,1000,1000*0d0/
      data         Ny,Boy/                 200,1000*0d0/
      data      Ymin,Ymax/               0.5d0,   1.5d0/
      dy=(Ymax-Ymin)/Ny
      Y(1)=Ymin
      do j=1,Ny
        Y(j+1)=Y(j)+dy
      enddo
      dx=(1d0-0d0)/N
      X(1)=0d0
      do j=1,N
        X(j+1)=X(j)+dx
      enddo
      do i=1,imax
        call ransu(iy,r)
!       write(*,*) i,r
        do j=1,N
          if(X(j).lt.r .and. r.le.X(j+1)) then
            Box(j)=Box(j)+1
            go to 1000
          endif
        enddo
 1000   continue
      enddo
      do j=1,N
        BoxP(j)=Box(j)/dx/imax  ! BoxP:Probability, Box:Number
      enddo
      open(1,file='ex08.dat')
      do j=1,N
        write(1,'(i4,1p4e12.4)') j, X(j), X(j)+dx/2, Box(j), BoxP(j)
      enddo
      close(1)
      do i=1,N
        s=BoxP(i)
        do j=1,Ny
          if(Y(j).lt.s .and. s.le.Y(j+1)) then
            Boy(j)=Boy(j)+1
            go to 2000
          endif
        enddo
 2000   continue
      enddo
      do j=1,Ny
        BoyP(j)=Boy(j)/dy/N
      enddo
      open(2,file='ex08a.dat')
      do j=1,Ny
        write(2,'(i4,1p4e12.4)') j, Y(j), Y(j)+dy/2, Boy(j), BoyP(j)
      enddo
      close(2)
      return
      end
      
      subroutine ransu(iy,r)
      implicit none
      integer iy
      real*8 r
      iy=iy*48828125
      if(iy.lt.0) iy=(iy+2147483647)+1
      r=dfloat(iy)*4.6566128e-10
      return
      end