Google
 

Trailing-Edge - PDP-10 Archives - decus_20tap1_198111 - decus/20-0013/drand.mac
There are 2 other files named drand.mac in the archive. Click here to see a list.
	TITLE	DRAND DOUBLE PRECISON RANDOM NUMBER
	SUBTTL	V.001  R.S.TOMLINSON.  19 AUG 68
	ENTRY	DRAND
	INTERN	DRAND
	EXTERN	RAND,DFA.2,DFM.0,DFA.0

;; CALL:	JSA 16,DRAND
;;	ARG 06,<LOWER LIMIT>
;;	ARG 06,<UPPER LIMIT>
;;	RESULT RETURNED IN AC 0,1
;;	USES PUSH DOWN POINTER IN AC 17

; Modified to PUSHJ/POPJ calling convention 11 Oct 1980
; by Paul T. Robinson, Wesleyan Univ. for DECUS conversion to DEC-20
; call:	movei	16,[<lower limit>
;		    <upper limit>]
;	pushj	17,drand
;arg returned as above

DRAND:	pushj	17,rand	; GET 36 RANDOM BITS
	PUSH 17,0	; SAVE THEM
	pushj	17,rand	; GET 36 MORE RANDOM BITS
	JFFO 0,DRAND1	; COUNT LEADING ZEROES AND JUMP IF NOT ALL ZERO
	POP 17,1	; CHECK LOW ORDER WORD
	JFFO 1,DRAND4	; COUNT LEADING ZEROES AND JUMP IF NON-ZERO
DRAND3:	PUSH 17,16	; SAVE AC 16
	MOVEI 3,@0(16)	; LOAD AC 3 WITH ADR OF LOWER LIMIT
	MOVE 2,0(3)	; PUT LOWER LIMIT INTO AC 2,3
	MOVE 3,1(3)
	DFN 2,3		; COMPLEMENT LOWER LIMIT
	MOVEI 16,@1(16)	; LOAD AC 16 WITH ADR OF UPPER LIMIT
	PUSHJ 17,DFA.2	; FORM <UPPER LIMIT> - <LOWER LIMIT>
	MOVEI 16,2
	PUSHJ 17,DFM.0	; TIMES RANDOM NUMBER FROM 0.0 TO 1.0
	MOVE 16,(17)	; RESTORE AC 16
	HRRZ 16,0(16)	; LOAD AC 16 WITH ADR OF LOWER LIMIT
	PUSHJ 17,DFA.0
	POP 17,16	; RESTORE AC 16
	popj	17,	; RETURN

DRAND1:	MOVE 2,1	; SAVE LEADING ZERO COUNT IN AC 2
	POP 17,1	; GET LOW ORDER WORD
	JRST DRAND2

DRAND4:	ADDI 2,^D36
DRAND2:	LSHC 0,-9(2)	; PUT HIGH ORDER ONE IN BIT 9
	LSH 1,-9	; CLEAR SIGN AND EXPONENT BITS
	MOVN 2,2
	FSC 0,200(2)
	FSC 1,200-^D27(2)
	JRST DRAND3

	END