(49G) Spectral Test for LCPRNG - Gerald H - 07-04-2015 11:38 AM
The programme STEST implements the spectral test for efficacy of LCPRNG presented in
Knuth: Seminumerical Algorithms, beginning at section 3.3.4, 3rd edition, 1998.
The programme takes three parameters, two integers stored in m, the modulus, & multiplier in a, eg
m = 339149426196985951
a = 967494892105817999
The third parameter is taken from the stack, an integer setting the number of dimensions of accuracy to be determined, from two upwards. Six should normally suffice.
For 6 the m & a above return
{ { 967494892105817999 339149426196985951 } "PASS" 305838803583608674 "PASS" 199091765810 "PASS" 519004521 "PASS" 3237231 "PASS" 229982 }
stored in STRES, indicating they are a good choice.
STEST has four sub-programmes, see below.
STEST
Code:
::
CK1&Dispatch
BINT1
::
ID a
DUPTYPEZINT?
NcaseTYPEERR
ID m
DUPTYPEZINT?
NcaseTYPEERR
DUP
FPTR2 ^ZSQ_
3UNROLL
DOCLLCD
"m="
OVER
FPTR2 ^Z>S
&$
BIGDISPROW1
"a="
3PICK
FPTR2 ^Z>S
&$
BIGDISPROW2
4ROLL
COERCE
BINT2
#MAX
BINT8
#MIN
BINT2
4PICK
DUPDUP
FPTR2 ^ZSQ_
Z1_
FPTR2 ^QAdd
6PICK
ZINT1_0_
BINT11
NDUPN
BINT10
#+
ROMPTR B0 DE
BEGIN
14GETLAM
DUP
17GETLAM
FPTR2 ^ZQUOText
DUP
11PUTLAM
17GETLAM
FPTR2 ^QMul
FPTR2 ^QSub
12GETLAM
11GETLAM
13GETLAM
FPTR2 ^QMul
ID x010
WHILE
::
15PUTLAM
17GETLAM
14PUTLAM
10GETLAM
17PUTLAM
13GETLAM
12PUTLAM
9GETLAM
13PUTLAM
;
REPEAT
DROP
10GETLAM
17GETLAM
FPTR2 ^QSub
9GETLAM
13GETLAM
ID x010
ITE
::
15PUTLAM
10GETLAM
14PUTLAM
9GETLAM
12PUTLAM
;
DROP
ID x00B
17GETLAM
FPTR2 ^RNEGext
13GETLAM
14GETLAM
FPTR2 ^RNEGext
12GETLAM
{
BINT2
BINT2
}
BINT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