Trailing-Edge
-
PDP-10 Archives
-
decuslib20-03
-
decus/20-0078/libsim/nextra.mac
There is 1 other file named nextra.mac in the archive. Click here to see a list.
COMMENT % SIMULA specification;
OPTIONS(/E:QUICK,nextrandom);
INTEGER PROCEDURE nextrandom(nstep,u); INTEGER nstep,u;
COMMENT Returns the NSTEP:th value from the random stream,
starting with U.
;
! BEGIN INTEGER an,acc;
! ! an saves actual product;
! ! acc saves a^(2^i) for i = 0,1,2...Log2[nstep]+1;
! ! nstep = sum(2^i) for certain i's;
! a:=5^15;
! b:=2^35;
! an:= 1;! acc:= a;
! nstep:= Mod(nstep,b//4); !Take Mod(cycle length = 2^33);
! WHILE nstep NE 0 DO
! BEGIN
! IF Mod(nstep,2) = 1 THEN an:= Mod(an*acc,b);
! acc:= Mod(acc*acc,b);
! nstep:= nstep//2; !Shift to next bit;
! END loop;
! nextrandom:= Mod(an*u,b);
! END of nextrandom;
!%;! MACRO-10 code !%;!
TITLE nextrandom
ENTRY nextrandom
SUBTTL SIMULA utility, Lars Enderin Mar 1976
;!*** Copyright 1976 by the Swedish Defence Research Institute. ***
;!*** Copying is allowed. ***
sall
search simmac,simmcr,simrpa
macinit
;! Local definitions ;!
nstep==XWAC1
u==XWAC2
an==XWAC3
acc==X0
a==1
REPEAT ^d15,<a==a*5>
nextrandom:
PROC
EXCH XWAC1,(XTAC)
EXCH XWAC2,1(XTAC)
SAVE <XWAC3,XWAC4>
LI an,1
L acc,[a]
TLZ nstep,700k ;! Zero 3 bits starting at bit 0
WHILE ;! nstep > 0
JUMPE nstep,FALSE
DO
IF ;! Last bit = 1
TRNN nstep,1
GOTO FALSE
THEN
MUL an,acc
L an,an+1
TLZ an,400k
FI
MUL acc,acc
L acc,acc+1
TLZ acc,400k
ASH nstep,-1
OD
L u
SKIPGE
ADD [377777777777]
TRO 1
MUL an
TLZ X1,400k
ST X1,XWAC1
RESTORE
EXCH XWAC2,1(XTAC)
EXCH XWAC1,(XTAC)
POPJ XPDP,
EPROC
LIT
END;