c-------------------------------------------------------------
c Chapter 6: Random composition of n into k parts(p53)
c-------------------------------------------------------------
c   Name of subroutine:  RANCOM
c
c   Algorithm:Generating random compsition of n into k parts
c
c   input:    n=6,k=3
c   number of calls: run=120
c   complier: f77 ranksb.f rancom_2.f 
c-------------------------------------------------------------

      parameter(n=6,k=3,run=120)
      integer r(n)
      do 20 i=1,run
      call rancom(n,k,r)
      write (*,*), (r(j),j=1,k)
   20 continue
      stop
      end

c-----Subroutine begins here----------------------------------
      subroutine rancom(n,k,r)
      integer r(k)
      call ranksb(n+k-1,k-1,r)
      r(k)=n+k
      l=0
      do 10 i=1,k
      m=r(i)
      r(i)=m-l-1
10    l=m
      return
      end


