c-----------------------------------------------------------
c Chapter 14: Young Tableaux (p117)
c-----------------------------------------------------------
c   Name of subroutine: RANYTB
c
c   Algorithm: Seclets, u.a.r., a Young tableau of 
c              given shape.
c
c   input:    n=6
c   number of calls: run=50 
c   complier: f77 ranytb_2.f
c-----------------------------------------------------------

        parameter(n=6,run=50 )
        integer lam(n),y(n)
        integer i
        lam(1) = 3
        lam(2) = 2 
        lam(3) = 1 

        do 50 i=1,run
        call ranytb (n, lam, y)
        write(*,30), (y(k),k=1,n)
30      format(10i2)
50      continue
        stop 
        end

c-------Subroutine begins here------------------------------
	subroutine ranytb(n, lam, y)
	integer lam(n), y(n), h 
	do 5 I=1, n 
5	y(i)=0
	i=0
	l=0
10	i=i+1
	m=lam(i)
	do 20 j=1,m
	y(j) = y(j)+1
20	l=l+1
	if (l .lt. n) go to 10
30	do 85 m = 1,n
40	i=1+rand(iseed)*y(1)
	j=1+rand(iseed)*lam(1)
41	if (i .gt. y(j) .or. j .gt. lam(i)) go to 40
70	h=y(j)+lam(i)-i-j
	if (h .eq. 0) go to 80
	l=1+h*rand(iseed)
	if (l .gt. lam(i)-j) go to 60
	j=j+l
	go to 70
60	i=l-lam(i)+1+j
79	go to 70
80	lam(i)=lam(i)-1
	y(j)=y(j)-1
85	y(n+1-m)=i
	do 90 i=1,n 
90	lam(y(i))=lam(y(i))+1
	return
	end

