integer   :: j,k,l,m(5),wc,ih
            
      real :: r(200)
      
      character(10) d,t
      character k1*8, fname1*80, fname2*80, fname3*80, line*22
 	character line1a1*23 ,line1a2*23 ,line1b*1,line2a*91
      character line3a*91,line4a*32, line5a*33 

      line1a1='background "rnd_image2"'
      line1a2='background "rnd_image3"'
      line1b='"'
      line2a='   command "-execute /usr/freeware/bin/xli -onroot '//
     1        '-fork /usr1/alberta/misc/images/rwindow/'
      line3a='   default "-execute /usr/freeware/bin/xli -onroot '//
     1        '-fork /usr1/alberta/misc/images/rwindow/'
      line4a='   exeok "/usr/freeware/bin/xli"'
      line5a='   readok "/usr/freeware/bin/xli"'
      
      open(11,file='/usr1/alberta/bin/pid.dat')
      read(11,*) ipid
      read(11,*) wc
      close(11)
       
    	call system_clock(count=k,count_rate=l,count_max=n)
      write(k1,'(i8.8)')k
      read(k1(5:8),'(i4)')k2

      do i=1,ipid*1000
       ii=ii+1
       end do
	call system_clock(count=j,count_rate=l,count_max=n)

	jk=abs(j-k)
      do while (jk.gt.31326)
       jk=jk/1.5
       end do
      
      
	m(1)=jk      
      m(2)=ipid
      m(3)=0
      m(4)=0
      m(5)=0

      call random_seed(put=m)
      call random_number(h1)
      ih1=int(h1*wc )+1
      
      ih2=ih1
	call mvbits(m(1),2,5,m(1),9)      
	call mvbits(m(2),1,4,m(2),9)      
      do while (m(1).gt.31326)
       m(1)=m(1)/1.5
       end do
      do while (m(2).gt.30080)
       m(2)=m(2)/1.5
       end do
      call random_seed(put=m)
	do while (ih2.eq.ih1)
       call random_seed(put=m)
       call random_number(h2)
       ih2=int(h2*wc )+1
       end do

      
      ih3=ih2     
	call mvbits(m(1),5,8,m(1),1)      
	call mvbits(m(2),5,8,m(2),1) 
      do while (m(1).gt.31326)
       m(1)=m(1)/1.5
       end do
      do while (m(2).gt.30080)
       m(2)=m(2)/1.5
       end do
      call random_seed(put=m)
	do while ((ih3.eq.ih2).or.(ih3.eq.ih1))
       call random_number(h3)
       ih3=int(h3*wc )+1
       end do

    	open(12,file='/usr1/alberta/bin/files.dat')
      do i=1,ih1
       read(12,'(a80)') fname1
       end do
      close(12)      

    	open(13,file='/usr1/alberta/bin/files.dat')
      do i=1,ih2
       read(13,'(a80)') fname2
       end do
      close(13)      

    	open(14,file='/usr1/alberta/bin/files.dat')
      do i=1,ih3
       read(14,'(a80)') fname3
       end do
      close(14)      

	idx1=index(fname1,' ')-1
	idx2=index(fname2,' ')-1
	idx3=index(fname3,' ')-1

	open(15,file='/usr1/alberta/.backgrounds') 
      iflag=0
      do while (iflag.eq.0)
       read(15,'(a22)') line
       if (line(13:22).eq.'rnd_image1') iflag=1
       end do
       
      write(15,902)line2a//fname1(1:idx1)//line1b
      write(15,902)line3a//fname1(1:idx1)//line1b
      write(15,903) line4a
      write(15,904) line5a
      write(15,*)
      write(15,901)line1a1
      write(15,902)line2a//fname2(1:idx2)//line1b
      write(15,902)line3a//fname2(1:idx2)//line1b
      write(15,903) line4a
      write(15,904) line5a
      write(15,*)
      write(15,901)line1a2
      write(15,902)line2a//fname3(1:idx3)//line1b
      write(15,902)line3a//fname3(1:idx3)//line1b
      write(15,903) line4a
      write(15,904) line5a
      write(15,*)
       
       

 901  format(a23)
 902  format(91a,a,1a)
 903  format(a32)
 904  format(a33)
       
      
                        
         stop
         end