c-----------------------------------------------------------
c Chapter 8: Random permutation of n letters(p63) 
c-----------------------------------------------------------
c   Name of subroutine: RANPER
c
c   Algorithm:Generating random permutation of 1,2,...n.
c
c   input:    n=3
c   number of calls: run=50
c   complier: f77 ranper_2.f
c-----------------------------------------------------------

      parameter(n=3,run=50)
      integer a(n) 
      do 50 i=1,run
      call ranper(n,a)
      write(*,*), (a(j),j=1,n)
   50 continue
      stop
      end

c-----Subroutine begins here--------------------------------
      subroutine ranper(n,a)
      integer a(n)
      do 10  i=1,n
10    a(i)=i
20    do 40  m=1,n
30    l=float(m)+rand(iseed)*float(n+1-m)
      l1=a(l)
      a(l)=a(m)
40    a(m)=l1
      return
      end

