      Program  Pokerov test
c    
      DIMENSION pole3(1:1000000)
      DIMENSION pole(1:1000000)
      DIMENSION pole2(1:1000000)
      integer*8 k,l,m,xs,xn,n
c
      write(*,*)"Zadaj tri cele cisla"
      read(*,*)k,l,m
c
      write(*,*)"Zadaj cele cislo ako zaciatok pre generator"
      read(*,*)xs
c
      OPEN(1,file="generator.dat")
      OPEN(2,file="generator2.dat")
      do i=1,1000000
         call  gen(k,l,m,xs,xx,yy,zz,p1,p2,p3,ff)
         xs=ff
         write(1,*)xx,yy,zz
         write(2,*)p1,p2,p3
      end do
      CLOSE(1)
      CLOSE(2)
   
      pp1=0
      pp2=0
      pp3=0
      OPEN(2,file="generator2.dat")   
      OPEN(1,file="generator.dat")
      OPEN(3,file="generator3.dat")
      do i=1,1000
         do j=1,1000
            read(2,*)p1,p2,p3
            call pravd(p1,p2,p3,pp1,pp2,pp3) 
         end do
         pp1=pp1/1000
         pp2=pp2/1000
         pp3=pp3/1000
         pole(i)=pp1
         pole2(i)=pp2
         pole3(i)=pp3 
         write(3,*)pp1,pp2,pp3
      end do
      CLOSE(1)   
      CLOSE(2)
      CLOSE(3)
 
      OPEN(3,file="generator3.dat")
      Ppp1=0.0
      Ppp2=0.0
      Ppp3=0.0

      do i=1,1000
         read(3,*)pp1,pp2,pp3
         Ppp1=Ppp1+pp1
         Ppp2=Ppp2+pp2
         Ppp3=Ppp3+pp3
      end do
      Ppp1=Ppp1/1000
      Ppp2=Ppp2/1000
      Ppp3=Ppp3/1000
c      write(*,*)Ppp1,Ppp2,Ppp3
      CLOSE(3)

      S1=0.0
      S2=0.0
      S3=0.0
      do i=1,1000
         S1=S1+((Ppp1-pole(i))*(Pp1-pole(i)))
         S2=S2+((Ppp2-pole2(i))*(Pp2-pole2(i)))
         S3=S3+((Ppp3-pole3(i))*(Pp3-pole3(i)))
      end do
      Sn1=sqrt(S1/999)
      Sn2=sqrt(S2/999)
      Sn3=sqrt(S3/999)
      write(*,*)"Pravdepodobnosti a odchýlky ",Ppp1,Ppp2,Ppp3,Sn1,Sn2,Sn3
      end
c xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
     

      Subroutine gen(i,j,n,mn,x,y,z,a,b,c,f)
      xn=mod(i*mn+j,n)
      x=real(xn)/real(n)
      mn=xn
      xn=mod(i*mn+j,n)
      y=real(xn)/real(n)
      mn=xn
      xn=mod(i*mn+j,n)
      z=real(xn)/real(n)
      mn=xn
      f=mn
      IF (x .LE. 1./3.) THEN
                 a=1
         ELSE IF (x .LE. 2./3.) THEN
                 a=2
         ELSE
                 a=3
         END IF

         if(y.LE.1./3.)then
                   b=1
         else if(y.LE.2./3.)then
                   b=2
              else
                   b=3
         end if

         if(z.LE.1./3.)then
                   c=1
         else if(z.LE.2./3.)then
                   c=2
              else
                   c=3
      end if
      end

      Subroutine pravd(x,y,z,v1,v2,v3)
      sum=0
      sum=x+y+z
      if (sum.EQ.3 .OR. sum.EQ.9) then
             v1=v1+1
      else if (sum.EQ.6) then
              if(x.EQ.y .AND. y.EQ.z) then
                      v1=v1+1
              else
                      v3=v3+1
              end if
      else
              v2=v2+1
      end if
      end  

 
