Randomicity Test Program for Pseudo-Random Number Generator ...

Report 2 Downloads 98 Views
F o r p r e s e n t a t i o n a t t h e L ' > ~ l l r i ~ e e t i u g 01 t h e A s s o c i a t i o n , Cambridge, England, August 1982.

Parapsychological

A Radomicity T e s t Program f o r Pseudo-Random Number G e n e r a t o r R o u t i n e s on t h e HP-41C C h a r l e s T. T a r t U n i v e r i s t y of C a l i f o r n i a , D a v i s The a v a i l a b i l i t y of h i g h q u a l i t y , r e l a t i v e l y i n e x p e n s i v e programmable s c i e n t i f i c c a l c u l a t o r s , such a s t h e Hewle t t - P a c k a r d tLP-41C, o f f e r s a v a l u a b l e new t o o l t o p a r a p s y c h o l o g i s t s . As d e s c r i b e d i n a n o t h e r p a p e r ( T a r t , 1 9 8 2 ) , t h e HP-41C c a n be programmed t o p r o v i d e a l a b o r a t o r y q u a l i t y ESP t e s t and f e e d b a c k A r a p i d e v o l u t i o n of f e a t u r e s a v a i l a b l e c a n t r a i n i n g instrument. be e x p e c t e d i n s u c h " c a l c u l a t o r s " ( t h e y a r e r e a l l y hand-held c o m p u t e r s ) , s o t h e y may p l a y a s t r o n g r o l e i n p a r a p s y c h o l o g i c a l research i n the near future. I n u s i n g t h e s e i n s t r u m e n t s f o r ESP t e s t i n g d e v i c e s , i t i s e s s e n t i a l t h a t they have high q u a l i t y s u b r o u t i n e s f o r g e n e r a t i n g A t p r e s e n t we a r e l i m i t e d t o pseudo-random random numbers. number g e n e r a t o r (PRNG) s u b r o u t i n e s , b u t w i t h a d e q u a t e a l g o r i t h m s f o r such r o u t i n e s and f r e q u e n t changing of quasi-random s e e d v a l u e s , i t s h o u l d n o t be too d i f f i c u l t t o g e n e r a t e a d e q u a t e l y random t a r g e t numbers. T h i s paper d e s c r i b e s a t e s t r o u t i n e f o r e v a l u a t i n g a PRNG. The s p e c i f i c program i s f o r t h e HP-41C, b u t i t s h o u l d be r e a d i l y a d a p t a b l e t o any programmable s c i e n t i f i c calculator. A t r u e RNG h a s two i m p o r t a n t properties. First, the p r o b a b i l i t y of any o u t p u t i s e q u a l t o t h a t of any o t h e r o u t p u t , s o a s a s e r i e s g e t s l o n g e r t h e p r o p o r t i o n of any p a r t i c u l a r o u t p u t t o t h e t o t a l o u t p u t a p p r o a c h e s 1 / C , where C i s t h e number Second, t h e r e i s no s e q u e n t i a l of o u t p u t c h o i c e s of t h e RNG. dependency be tween numbers, t h a t i s , t h e p r o b a b i l i t y of any number f o l l o w i n g some p r e v i o u s o u t p u t number o r s e q u e n c e of such numbers i s e q u a l t o t h a t of any o t h e r number f o l l o w i n g t h a t p r e v i o u s o u t p u t number o r sequence of numbers. T h i s a l s o means t h a t no m a t t e r what o u t p u t numbers have a l r e a d y been g e n e r a t e d , t h e y g i v e you no u s e f u l way of p r e d i c t i n g what t h e n e x t o u t p u t s w i l l be. ( F o r f u l l e r d i s c u s s i o n of the non-predictability c r i t e r i o n s e e T a r t , 1979a; 1979b; T a r t & Dronek, 1 9 8 0 ) . The adequacy of a RNG o r PRNG can be e v a l u a t e d s t a t i s t i c a l l y by t e s t i n g a l a r g e sample of o u t p u t s f o r e q u i p r o b a b i l i t y and l a c k A common way of d o i n g t h i s t e s t i n g i s of s e q u e n t i a l dependency. t o count up n o t o n l y s i n g l e o u t p u t s ( 9 , I s , 2 s , e t c . , c a l l e d s i n g l e t s ) , b b t a l s o s e q u e n t i a l o u t p u t s ( 9 f o l l o w e d by 9 , Q) followed by 1, Q) f o l l o w e d by 2 , etc., called doublets). Sequential output t e s t i n g u s u a l l y includes doublets, and, i f t h e r e is a t h e o r e t i c a l reason t o suspect higher order sequential dependencies, t r i p l e t s , q u a d r u p l e t s , e t c .

The f o l l o w i n g t e s t program was d e s i g n e d t o check t h e PRNG s u b r o u t i n e u s e d i n a n ESP t e s t program d e s c r i b e d e l s e w h e r e ( T a r t & Puthoff, 1981; Tart, 1982), where n o n p r e d i c t a b i l i t y is extremely important. It r e q u i r e s a p r i n t e r and e x t e n d e d memory. By p u t t l n g i n y o u r own PRNG s u b r o u t i n e a s s t e p 056 and c a l l i n g i t LBL 0 5 , s u b s t i t u t i n g f o r s t e p s g56 t h r o u g h 066 i n t h e p r e s e n t program, you c a n t e s t i t . The t e s t program assumes t h a t your PRNG p r o d u c e s a n i n t e g e r (no f r a c t i o n a l p a r t ) o u t p u t , which a p p e a r s a s s t e p 67 i n t h i s t e s t program. The p a r t i c u l a r PRNG s u b r o u t i n e w r i t t e n i n t o t h i s program s t a r t s w i t h a s e e d number t h a t i s s t o r e d i n r e g i s t e r 09. The a l g o r i t h m i s d e s c r i b e d i n T a r t , 1982. It p r o d u c e s a f r a c t i o n a l o u t p u t between .99999999 and 1 , but the s c a l i n g f a c t o r (number of c h o i c e s ) s t o r e d i n r e g i s t e r $38 s c a l e s t h i s u p t o t h e p r o p e r c h o i c e r a n g e , and t h e INT ( i n t e g e r ) f u n c t i o n i n t h e HP-41C d i s c a r d s t h e f r a c t i o n a l p a r t of t h e number produced. I use t h e time, t o t h e n e a r e s t second, a s a quasi-random way of g e t t i n g a s e e d number f o r e a c h r u n of t h e PRNG t h a t i s r e l a t i v e l y i n d e p e n d e n t of any d e l i b e r a t e c o n t r o l o n my p a r t . Operation: D e t a i l e d o p e r a t i o n n o t e s a r e l i s t e d w i t h t h e program. Size 4161 s h o u l d be e x e c u t e d b e f o r e r u n n i n g i t . B r i e f l y , t h e TESTRNG program s t a r t s w i t h h o u s e k e e p i n g c h o r e s of c l e a r i n g r e g i s t e r s a n d f l a g s , t h e n prompts f o r t h e t o t a l number of o u t p u t s , t r i a l s , wanted from t h e PRNG (TOTAL N?) i n t h i s r u n , f o r t h e number of c h o i c e s ( 2 t o 1 0 ) t h e PRNG i s t o h a v e , w h e t h e r you want t h e raw PRNG o u t p u t p r i n t e d ( e n t e r " N u f o r n o , o t h e r w i s e j u s t p r e s s R / S ) , and w h e t h e r you want t h e PRNG o u t p u t a c c u m u l a t e d f o r l a t e r "N" for no, statistical analysis (ANALYZE?) ( a g a i n e n t e r o t h e r w i s e R/S) A n o t e on l i m i t a t i o n s . A s i n g l e t a n a l y s i s c a n be c a r r i e d o u t i f y o u r PRNG o u t p u t i s @ t o 9 , b u t TESTRNG c a n c a r r y o u t a d o u b l e t a n a l y s i s o n l y i f t h e r e a r e no more t h a n 5 c h o i c e s !l t o 4 ) . D o u b l e t a n a l y s i s w i l l be a u t o m a t i c a l l y s k i p p e d (outputs L i f C > 5. T h i s i s due t o t h e d i f f i c u l t y of a d d r e s s i n g enough r e g i s t e r s : a s i t i s , r e g i s t e r s 00 t h r o u g h 6.g ( s i z e 0 6 1 ) a r e used. I n g e n e r a l I s u s p e c t t h a t i f your PRNG r o u n t i n e shows no s i n g l e t o r d o u b l e t b i a s e s f o r o u t p u t s $3 t h r o u g h 4 i t p r o b a b l y d o e s n ' t h a v e them f o r o u t p u t s 5 t h r o u g h 9 , b u t d o n ' t c o u n t on i t . The TESTRNG program t h e n prompts f o r a t i m e o r o t h e r s e e d number (SEED?), f o l l o w i n g which i t a c c e s s e s t h e PKNG s u b r o u t i n e T h i s c a n t a k e a w h i l e . F o r my u n t i l i t has c o l l e c t e d N outputs. p a r t i c u l a r PRNG s u b r o u t i n e , i t t a k e s a b o u t 4 m i n u t e s t o c o l l e c t 10Q o u t p u t s . When N o u t p u t s a r e p r e s e n t t h e t o t a l number of

.

o u t p u t s t o d a t e a r e p r i n t e d ( Z Z = ) and a beep s i g n a l s t h a t a new s e e d i s wanted. T o t a l o u t p u t s e q u a l N on t h e f i r s t r u n of TESTRNG. T h i s f e a t u r e e x i s t s b e c a u s e I u s u a l l y u s e my PRNG i n t h e ESP t e s t program f o r r u n s of 25 t r i a l s o r l e s s and t h e n e n t e r a new t i m e s e e d f o r e a c h r u n t o a s s u r e b e t t e r r a n d o m i c i t y . Your N shoul'd be t h e u s u a l number of o u t p u t s you u s e a t a t i m e from y o u r PRNG, o r a n e v e n l a r g e r sample. A t t h i s p o i n t you can e n t e r a new t i m e s e e d and g e t N more o u t p u t s from t h e PRNG. For a n a l y s i s purposes, t h e s e o u t p u t s a r e For accumulated w i t h t h e p r e c e e d i n g b a t c h e s of N o u t p u t s . example, i f you used a b i n a r y PRNG and i n 100 t r i a l s had 48 @s and 52 I s , t h e n r a n a n o t h e r 100 t r i a l s w i t h 46 0s and 54 I s , t h e s t o r a g e r e g i s t e r s would c u m u l a t e 94 fls and 106 Is. I f you e l e c t e d t o s t o r e d a t a f o r a n a l y s i s , a t t h e end of any r u n of N t r i a l s you c a n XEQ " C H I " t o s t a r t a n a l y s i s of t h e cumulated r e s u l t s . T h i s a n a l y s i s does n o t a f f e c t d a t a s t o r a g e r e g i s t e r s , s o you c a n c u m u l a t e more d a t a a f t e r s u c h a n a n a l y s i s . C H I i s a C h i - s q u a r e s t a t i s t i c a l t e s t a t t h e s i n g l e t and ( i f C < The r e s u l t i n g v a l u e s of C h i - s q u a r e c a n b e 5 ) the doublet levels. l o o k e d up i n any t a b l e . Note a l s o t h a t i f t h e e x p e c t e d v a l u e of any p a r t i c u l a r PRNG o u t p u t i s l e s s t h a n 5 , t h e C h i - s q u a r e t e s t i s g e n e r a l l y n o t v a l i d : t h e TESTRNG program w i l l a u t o m a t i c a l l y p r i n t "E < 5" t o a l e r t you when t h i s happens. Example : H e r e ' s a n example of TESTRNG's o p e r a t i o n . Run 2fl t r i a l s of a 3-choice PRNG and a n a l y z e , u s i n g t h e c u r r e n t PRNG s u b r o u t i n e . The PRNG raw o u t p u t p r i n t e d i s The time s e e d i s 935.54. 2 . 1. 2. 8. 1. 2. 1. 1. 1. 0. 1. 8. 1. 2. 1. 2. 0. 2. 2. 1. Upon e x e c u t i n g " C H I " t h e p r i n t e r g i v e s u s 4. 9. 7. S CHI SQ = 1.900 i n d i c a t i n g t h a t 0 was g e n e r a t e d 4 t i m e s , 1 was g e n e r a t e d 9 t i m e s , and 2 was g e n e r a t e d 7 t i m e s . The Chi-square a n a l y s i s u s e s t h e f o rmula 2 Chi-square = E F o r e a c h p o s s i b l e o u t p u t c a t e g o r y ( 0 , 1, o r 2 i n t h i s c a s e ) t h e o b s e r v e d number of a p p e a r a n c e s of t h a t o u t p u t ( 0 ) h a s t h e e x p e c t e d numb'er of a p p e a r a n c e s ( E , 2813 i n t h i s c a s e ) s u b t r a c t e d from i t , t h e r e s u l t i s s q u a r e d and t h e n d i v i d e d by E , and t h e r e s u l t s a r e summated f o r a l l p o s s i b l e o u t p u t s .

The d o u b l e t a n a l y s i s s u b r o u t i n e t h e n p r i n t s o u t 0. 3 . 1. 2. 2. 4. 2. 4. 1. D CHI SQ = 7.p153 E < 5 i n d i c a t i n g t h a t a n o u t p u t of 0 was f o l l o w e d by 0 z e r o times, $? was f o l l o w e d by 1 t h r e e times, 1 was f o l l o w e d by two t i m e s , etc. C h i - s q u a r e i s computed by t h e same f o r m u l a , but n o t e t h a t we o n l y have 19 d o u b l e t s i n 20 t r i a l s , a n d we sum o v e r 9 o u t p u t categories. Because t h e e x p e c t e d f r e q u e n c i e s i n e a c h c a t e g o r y w e r e less t h a n 5 , "E < 5 " i s p r i n t e d o u t a s a w a r n i n g t h a t t h i s particular analysis is not valid. Testing External Generators: The TESTRNG program c a n a l s o be used t o a n a l y z e a n e x t e r n a l l y g e n e r a t e d s e t of random numbers w i t h t h e f o l l o w i n g m o d i f i c a t i o n . F o r t h e c u r r e n t s t e p s 58 t o 67, p u t i n i n s t e a d 5 8 "NUMBER?" 59 PROMPT The program w i l l renumber i t s e l f i n t h e HP-41C s o t h e n e x t s t e p 6fl w i l l be t h e f o r m e r s t e p 6 8 , v i z . ST0 16. On e a c h c y c l e , which t a k e s a b o u t a s e c o n d , t h e program w i l l prompt you t o e n t e r a n i n t e g e r number, "NUNBER?" E n t e r y o u r e x t e r n a l g e n e r a t o r ' s o u t p u t a n d p r e s s R/S. I hope o t h e r r e s e a r c h e r s w i l l f i n d t h i s program u s e f u l .

The TESTRNG Program:

01

LBL "TESTRNG" 02 CF 'JQ 413 CF 'J1 414 CF 'J2 9 5 CF 'J3 416 'J.059'Jl 07 ST0 60 0 8 LBL 412 8 9 'J 10 ST0 I N D 6 0 11 ISG 6 0 1 2 GTO 412 1 3 FIX 'J 14 "TOTAL N ? " 1 5 PROMPT 16 ST0 'J5 1 7 LBL 07 1 8 "CHOICES?" 1 9 PROMPT 20 ST0 'J8 21 1 22 23 ST0 46 24 19 2 5 RCL 418 26 X > Y ? 27 GTO 'J7 28 5 29 RCL 418 3 0 X>Y? 3 1 SF 02 32 "N" 3 3 ASTO Y 34 AON 3 5 "PRINT RAW?" 3 6 PKOMPT 37 AOFF 38 ASTO X 39 X=Y? 40 SF 'Jg

C l e a r f l a g s , s t o r e loop c o n t r o l for register clear.

'

Loop f o r s t o r i n g 'Js i n r e g i s t e r 'J0 t h r o u g h 59.

Prompts f o r number of o u t p u t s of PRNG, c h o i c e s , C.

Computes and s t o r e s C - 1 f o r l a t e r computational ease. L i m i t s C t o maximum of

10.

T e s t : C > 5 ? I f s o , no d o u b l e t a n a l y s i s d a t a w i l l he s t o r e d .

Should raw PRNG ouput be p r i n t e d ? i f n o t , R/S i f you want i t .

E n t e r "N"

4 1 "N" 4 2 ASTO Y 4 3 AON 4 4 "ANALYZE ? " 45 P ~ O M P T 46 A O ~ F 47 ASTO X 48 X=Y? 49 SF 01 5 0 LBL 411 5 1 TONE 6 52 "SEED?" 53 PROMPT 54 LN 5 5 ABS 56 ST0 09 57 LBL 415 5 8 PI 59 RCL 419 6@+ 61 5 62 Y!X 6 3 FRC 6 4 ST0 0 9 6 5 KCL 418 66 67 INT 6 8 ST0 1 6 6 9 FS? 00 7 0 GTO 04 7 1 LBL 413 72 ACX 73 1 74 SKPCIIR 7 5 LBL 414 76 1 77 ST+ 06 7 8 FS? 01 79 GTO 06 8 @ RCL 1 6 8 1 50 82 + 8 3 ST0 17 84 1 85 ST+ I N D 17 8 6 FS? 02 87 GTO 11

S h o u l d s i n g l e t and d o u b l e t d a t a be s t o r e d f o r a n a l y s i s ? E n t e r "N" i f n o t , R/S i f you want i t .

P r o m p t s f o r a s e e d v a l u e f o r t h e PRNG.

Pseudo-Kandom Number G e n e r a t o r , PRNG r o u t i n e . Your r o u t i n e s h o u l d be e n t e r e d h e r e . This one t a k e s transformed s e e d from r e g . 09, a d d s p i , r a i s e s sum t o 5 t h power and s t o r e s f r a c t i o n a l p a r t i n reg. 09. L i n e s 65-67 s c a l e r e s u l t t o r a n g e of C and t a k e i n t e g e r

.

*

T e s t : a c c u m u l a t e PRNG o u t p u t f o r l a t e r analysis? Accumulate PRNG o u t p u t i n p r i n t b u f f e r , with spaces, for l a t e r printing.

Increment t r i a l s counter (reg. 06) by one. T e s t : a n a l y s i s wanted? Add 5 0 t o PRNG o u t p u t number t o g e t c o n t r o l number s o p r o p e r s i n g l e t c o u n t r e g i s t e r w i l l be i n c r e m e n t e d . I n c r e m e n t by o n e .

T e s t : d o u b l e t a n a l y s i s OK?

Tart -7

8 8 RCL Q6 89 1 90 X=Y? 9 1 G T O 06 92 RCL 18 9 3 Km 16 , 94 + 95 ST0 1 9 96 1 97 ST+ I N D 1 9 9 8 LBL 06 99 RCL 16

188 18 101 *

T e s t : f i r s t t r i a l of r u n ? I f s o , s k i p l i n e s 91-96 t o i n c r e m e n t a d o u b l e t register. Add l 0 x p r e v i o u s PRNG o u t p u t t o c u r r e n t PRNG ouput t o d e t e r m i n e d o u b l e t s t o r a g e r e g i s t e r number. Increment a p p r o p r i a t e d o u b l e t r e g i s t e r by one. M u l t i p l y c u r r e n t PRNG o u t p u t by l Q ,s t o r e , u s e f o r d o u b l e t i n c r e m e n t a d d r e s s i n g on next t r i a l .

102 ST0 1 8 1V)3 LBL 11 104 RCL Q6 1 0 5 RCL 0 5 106 X>Y? 1V)7 GTO 05 1 0 8 PRBUF 109 RCL (216 110 ST+ 07 111 RCL 07 112 "SC = " 113 ARCL X 114 AVIEW 115 0 116 ST0 Q6 1 1 7 GTO 01 1 1 8 LBL " C H I " 119 0 1.20 ST0 26 1 2 1 ST0 35 122 5(6 1 2 3 ST0 27 124 RCL 46 125 + 126 1 E3 127 / 128 1 E-5 129 + 1 3 0 ST+ 27' 1 3 1 ST0 28 132 KCL 97 1 3 3 RCL Q 8 134 / 135, ST0 25

T e s t : end of r u n ? PRNG o u t p u t .

I f not, a c t i v a t e another

P r i n t accumulated PRNG o u t p u t . Add t r i a l s of c u r r e n t r u n t o grand t r i a l s counter. P r i n t g r a n d t o t a l of PRNG t r i a l s t o d a t e .

Reset t r i a l s counter t o

0.

CHI-SQUARE ANALYSES C l e a r Chi-square

total registers.

Compute c o n t r o l number f o r i n d i r e c t KCL of s i n g l e t r e g i s t e r s 50 t h r o u g h 5@+(C-1).

i/ = (5gC

Lc-11

+

,00001

1,800 = 50.QQ(C-1)01

Computed e x p e c t e d s i n g l e t f r e q u e n c y , E , where E=N / C

T a r t -8

136 5 137 X>Y? 138 SF @ 3 139 LBL 0 8 14@ RCL I N D 27 1 4 1 ACX 142 1 143 SKPCHK 144 RCL I N D 27 145 RCL 25 146 147 ~ t 2 148 RCL 25 149 / 150 ST+ 26 1 5 1 ISG 27 152 GTO @ 8 153 FIX 3 154 PRBUF 155 RCL 26 156 "S C H I SQ= 157 AKCL X 158 AVIEW 159 PSE 160 CLA 1 6 1 FIX fl 162 FS? 9)3 163 XEQ 1 3 164 CF 9)3 1 6 5 FS? 02 1 6 6 GTO 12 167 RCL 07 168 ENTER+ 169 ENTER+ 17(b RCL 0 5 171 1 172 173 RCL 0 8 174 x t 2 175 / 1 7 6 ST0 25 177 5 178 X>Y? 179 SF @ 3

T e s t : E