Trailing-Edge
-
PDP-10 Archives
-
decuslib20-01
-
decus/20-0025/rand.mac
There are 5 other files named rand.mac in the archive. Click here to see a list.
TITLE RAND RANDOM NUMBER GENERATOR
SUBTTL B.E -21.OCTOBER 1970
;modified 14 sept 80 to pushj/popj calling convention
;for decus by paul t. robinson, wesleyan univ.
;modifications in lower case
;DRAND.F4 IS A SAMPLE PROGRAM, WHEN USED IN CONJUNCTION
;WITH RAND.MAC(LOADED AND SAVED AS DRAND.SAV) WILL
;ILLUSTRATE THE USE OF RAND.MAC
;MULTIPLICATIVE CONGRUENTIAL RANDOM NUMBER GENERATOR TO
;BE CALLED AS A FUNCTION FROM A FORTRAN PROGRAM. THERE
;ARE TWO ENTRY POINTS:
; 1) IRAND RETURNS A RANDOM INTEGER BETWEEN
; 0 AND 2**35 - 1.
; 2) RAND RETURNS A RANDOM FLOATING POINT NUM-
; BER BETWEEN 0.0 AND 1.0.
;BOTH CALLS REQUIRE A SINGLE INTEGER ARGUMENT WHICH
;IS USED TO GENERATE A RANDOM INTEGER BY MEANS OF THE
;FORMULA:
; R = (5**13)*ARG (MOD 2**35)
;THE RANDOM INTEGER THUS GENERATED IS STORED OVER
;THE ARGUMENT TO BECOME THE ARGUMENT FOR THE NEXT CALL,
;HENCE THE ARGUMENT MUST APPEAR IN THE CALLING SEQUENCE
;AS A VARIABLE RATHER THAN A CONSTANT. IF THE CALL
;WAS TO RAND, THE NEW RANDOM INTEGER IS CONVERTED TO A
;FLOATING POINT NUMBER BETWEEN 0.0 AND 1.0 BEFORE
;RETURNING. VIDE GORENSTEIN, "TESTING A RANDOM NUMBER
;GENERATOR", COMM ACM, FEB 67.
EXTERNAL .JBAPR
ENTRY RAND,IRAND
RAND: SETOM FPFLAG# ;SET FLOATING POINT SWITCH
caia
IRAND: SETZM FPFLAG ;SET INTEGER SWITCH
JSR IRAND2 ;JSR IN ORDER TO PRESERVE FLAGS
popj 17,
IRAND2: Z
MOVE 0,@(16) ;GET ARG
SKIPN 0 ;ARG=0?
MOVEI 0,1 ;YES - RESTART
MOVE 1,.JBAPR ;FOUL FLAG-TRAPPING
MOVEM 1,FLAGS#
MOVEI 1,IRAND3
MOVEM 1,.JBAPR
IMUL 0,CON ;GENERATE NEXT NUMBER
IRAND3: MOVE 1,FLAGS
MOVEM 1,.JBAPR
TLZ 0,400000 ;MAKE SURE IT'S POSITIVE
MOVEM 0,@(16) ;PUT IT AWAY FOR NEXT CALL
SKIPN FPFLAG ;INTEGER ANSWER REQUIRED?
JRST 2,@IRAND2 ;YES - RETURN WITH IT
LSH 0,-10 ;NO - CONVERT TO FLOATING POINT
FSC 0,200 ;AND DIVIDE BY 2**35
JRST 2,@IRAND2 ;RESTORE FLAGS & RETURN
CON: 5*5*5*5*5*5*5*5*5*5*5*5*5
END