C	GENERATE A BINOMIAL SAMPLE WITH PROBABILITY P AND
C	GIVEN SAMPLE SIZE(LESS THAN 100)
	DIMENSION LSAMP(100)
	K=314159267
	LETH='H'
	LETT='T'
	TYPE 1000
1	TYPE 1001
	ACCEPT 1002,N,P
	SN=N
	IF(SN*P) 2,2,3
2	CALL EXIT
3	N=MIN0(MAX0(1,N),100)
	P=AMIN1(AMAX1(.0001,P),.9999)
	NHEAD=0
	NTAIL=0
	DO 6 I=1,N
	IF(P-RAND(K))5,5,4
4	NHEAD=NHEAD+1
	LSAMP(I)=LETH
	GO TO 6
5	NTAIL=NTAIL+1
	LSAMP(I)=LETT
6	CONTINUE
	TYPE 1006,NHEAD,NTAIL,(LSAMP(I),I=1,N)
	GO TO 1
1000	FORMAT(' GENERATE A RANDOM SAMPLE OF HEADS AND
	1 TAILS'/' FROM A BINOMIAL DISTRIBUTION WITH
	2 GIVEN P')
1001	FORMAT(/' GIVE N AND P',$)
1002	FORMAT(I,F)
1006	FORMAT(' SAMPLE HAS',I3,' HEADS AND',I3,' TAILS'/
	1(10X,20A2))
	END
