Hex Artifact Content
Not logged in

Artifact af55930880b3b7452f9424331a05c4c77d4d95c4:


0000: 23 21 72 36 72 73 0a 28 69 6d 70 6f 72 74 20 28  #!r6rs.(import (
0010: 72 6e 72 73 29 20 28 72 6e 72 73 20 72 35 72 73  rnrs) (rnrs r5rs
0020: 29 20 28 73 75 72 66 61 67 65 20 73 32 37 20 72  ) (surfage s27 r
0030: 61 6e 64 6f 6d 2d 62 69 74 73 29 29 0a 0a 3b 20  andom-bits))..; 
0040: 43 4f 4e 46 49 44 45 4e 43 45 20 54 45 53 54 53  CONFIDENCE TESTS
0050: 20 46 4f 52 20 53 52 46 49 2d 32 37 20 22 53 6f   FOR SRFI-27 "So
0060: 75 72 63 65 73 20 6f 66 20 52 61 6e 64 6f 6d 20  urces of Random 
0070: 42 69 74 73 22 0a 3b 20 3d 3d 3d 3d 3d 3d 3d 3d  Bits".; ========
0080: 3d 3d 3d 3d 3d 3d 3d 3d 3d 3d 3d 3d 3d 3d 3d 3d  ================
0090: 3d 3d 3d 3d 3d 3d 3d 3d 3d 3d 3d 3d 3d 3d 3d 3d  ================
00a0: 3d 3d 3d 3d 3d 3d 3d 3d 3d 3d 3d 3d 3d 0a 3b 0a  =============.;.
00b0: 3b 20 53 65 62 61 73 74 69 61 6e 2e 45 67 6e 65  ; Sebastian.Egne
00c0: 72 40 70 68 69 6c 69 70 73 2e 63 6f 6d 2c 20 32  r@philips.com, 2
00d0: 30 30 32 2e 0a 3b 0a 3b 20 54 68 69 73 20 66 69  002..;.; This fi
00e0: 6c 65 20 63 6f 6e 74 61 69 6e 73 20 61 20 73 6d  le contains a sm
00f0: 61 6c 6c 20 63 6f 6c 6c 65 63 74 69 6f 6e 20 6f  all collection o
0100: 66 20 63 68 65 63 6b 73 20 66 6f 72 20 74 68 65  f checks for the
0110: 0a 3b 20 69 6d 70 6c 65 6d 65 6e 74 61 74 69 6f  .; implementatio
0120: 6e 20 6f 66 20 53 52 46 49 2d 32 37 2e 20 49 74  n of SRFI-27. It
0130: 20 69 73 20 6e 6f 74 20 6d 65 61 6e 74 20 74 6f   is not meant to
0140: 20 62 65 20 63 6f 6d 70 6c 65 74 65 0a 3b 20 6f   be complete.; o
0150: 72 20 74 6f 20 74 65 73 74 20 74 68 65 20 61 63  r to test the ac
0160: 74 75 61 6c 20 70 72 6f 70 65 72 74 69 65 73 20  tual properties 
0170: 6f 66 20 74 68 65 20 75 6e 64 65 72 6c 79 69 6e  of the underlyin
0180: 67 20 67 65 6e 65 72 61 74 6f 72 2e 0a 3b 20 49  g generator..; I
0190: 74 20 69 73 20 6d 65 72 65 6c 79 20 6d 65 61 6e  t is merely mean
01a0: 74 20 74 6f 20 72 75 6e 20 74 68 65 20 63 6f 64  t to run the cod
01b0: 65 20 61 6e 64 20 74 6f 20 63 68 65 63 6b 20 73  e and to check s
01c0: 6f 6d 65 20 6f 66 20 74 68 65 0a 3b 20 61 73 73  ome of the.; ass
01d0: 75 6d 70 74 69 6f 6e 73 20 6d 61 64 65 20 62 79  umptions made by
01e0: 20 73 70 65 63 69 66 69 63 61 74 69 6f 6e 2e 20   specification. 
01f0: 54 68 65 72 65 20 69 73 20 61 6e 20 69 6e 74 65  There is an inte
0200: 72 66 61 63 65 20 74 6f 0a 3b 20 47 2e 20 4d 61  rface to.; G. Ma
0210: 72 73 61 67 6c 69 61 27 73 20 44 49 45 48 41 52  rsaglia's DIEHAR
0220: 44 20 62 61 74 74 65 72 79 20 6f 66 20 74 65 73  D battery of tes
0230: 74 73 20 66 6f 72 20 72 61 6e 64 6f 6d 20 6e 75  ts for random nu
0240: 6d 62 65 72 0a 3b 20 67 65 6e 65 72 61 74 6f 72  mber.; generator
0250: 73 2c 20 74 68 6f 75 67 68 2e 0a 0a 3b 20 48 69  s, though...; Hi
0260: 73 74 6f 72 79 20 6f 66 20 74 68 69 73 20 66 69  story of this fi
0270: 6c 65 3a 0a 3b 20 20 20 53 45 2c 20 31 39 2d 4d  le:.;   SE, 19-M
0280: 61 72 2d 32 30 30 32 3a 20 69 6e 69 74 69 61 6c  ar-2002: initial
0290: 20 76 65 72 73 69 6f 6e 2c 20 62 61 73 65 64 20   version, based 
02a0: 6f 6e 20 65 61 72 6c 69 65 72 20 74 65 73 74 73  on earlier tests
02b0: 0a 3b 20 20 20 53 45 2c 20 32 32 2d 4d 61 72 2d  .;   SE, 22-Mar-
02c0: 32 30 30 32 3a 20 61 64 61 70 74 65 64 20 74 6f  2002: adapted to
02d0: 20 6e 65 77 20 70 72 6f 63 65 64 75 72 65 20 6e   new procedure n
02e0: 61 6d 65 73 0a 3b 20 20 20 53 45 2c 20 32 35 2d  ames.;   SE, 25-
02f0: 4d 61 72 2d 32 30 30 32 3a 20 6d 6f 72 65 20 64  Mar-2002: more d
0300: 65 73 63 72 69 70 74 69 76 65 20 6f 75 74 70 75  escriptive outpu
0310: 74 0a 3b 20 20 20 53 45 2c 20 30 34 2d 41 70 72  t.;   SE, 04-Apr
0320: 2d 32 30 30 32 3a 20 73 6f 6d 65 20 71 75 69 63  -2002: some quic
0330: 6b 20 74 69 6d 69 6e 67 73 3b 20 63 68 65 63 6b  k timings; check
0340: 20 75 70 0a 0a 3b 20 28 63 68 65 63 6b 20 65 78   up..; (check ex
0350: 70 72 29 0a 3b 20 20 20 20 65 76 61 6c 73 20 65  pr).;    evals e
0360: 78 70 72 20 61 6e 64 20 69 73 73 75 65 73 20 61  xpr and issues a
0370: 6e 20 65 72 72 6f 72 20 69 66 20 69 74 20 69 73  n error if it is
0380: 20 6e 6f 74 20 23 74 2e 0a 0a 23 3b 0a 28 64 65   not #t...#;.(de
0390: 66 69 6e 65 20 28 63 68 65 63 6b 20 65 78 70 72  fine (check expr
03a0: 29 0a 20 20 28 69 66 20 28 6e 6f 74 20 28 65 71  ).  (if (not (eq
03b0: 3f 20 28 65 76 61 6c 20 65 78 70 72 20 28 69 6e  ? (eval expr (in
03c0: 74 65 72 61 63 74 69 6f 6e 2d 65 6e 76 69 72 6f  teraction-enviro
03d0: 6e 6d 65 6e 74 29 29 20 23 74 29 29 0a 20 20 20  nment)) #t)).   
03e0: 20 20 20 28 65 72 72 6f 72 20 22 63 68 65 63 6b     (error "check
03f0: 20 66 61 69 6c 65 64 22 20 65 78 70 72 29 29 29   failed" expr)))
0400: 0a 0a 3b 20 42 61 73 69 63 20 54 65 73 74 73 20  ..; Basic Tests 
0410: 6f 66 20 74 68 65 20 49 6e 74 65 72 66 61 63 65  of the Interface
0420: 0a 3b 20 3d 3d 3d 3d 3d 3d 3d 3d 3d 3d 3d 3d 3d  .; =============
0430: 3d 3d 3d 3d 3d 3d 3d 3d 3d 3d 3d 3d 3d 3d 3d 0a  ===============.
0440: 0a 28 64 65 66 69 6e 65 20 28 6d 79 2d 72 61 6e  .(define (my-ran
0450: 64 6f 6d 2d 69 6e 74 65 67 65 72 20 6e 29 0a 20  dom-integer n). 
0460: 20 28 6c 65 74 20 28 28 78 20 28 72 61 6e 64 6f   (let ((x (rando
0470: 6d 2d 69 6e 74 65 67 65 72 20 6e 29 29 29 0a 20  m-integer n))). 
0480: 20 20 20 28 69 66 20 28 3c 3d 20 30 20 78 20 28     (if (<= 0 x (
0490: 2d 20 6e 20 31 29 29 0a 20 20 20 20 20 20 20 20  - n 1)).        
04a0: 78 0a 20 20 20 20 20 20 20 20 28 65 72 72 6f 72  x.        (error
04b0: 20 22 28 72 61 6e 64 6f 6d 2d 69 6e 74 65 67 65   "(random-intege
04c0: 72 20 6e 29 20 72 65 74 75 72 6e 65 64 20 69 6c  r n) returned il
04d0: 6c 65 67 61 6c 20 76 61 6c 75 65 22 20 78 29 29  legal value" x))
04e0: 29 29 0a 0a 28 64 65 66 69 6e 65 20 28 6d 79 2d  ))..(define (my-
04f0: 72 61 6e 64 6f 6d 2d 72 65 61 6c 29 0a 20 20 28  random-real).  (
0500: 6c 65 74 20 28 28 78 20 28 72 61 6e 64 6f 6d 2d  let ((x (random-
0510: 72 65 61 6c 29 29 29 0a 20 20 20 20 28 69 66 20  real))).    (if 
0520: 28 3c 20 30 20 78 20 31 29 0a 20 20 20 20 20 20  (< 0 x 1).      
0530: 20 20 78 0a 20 20 20 20 20 20 20 20 28 65 72 72    x.        (err
0540: 6f 72 20 22 28 72 61 6e 64 6f 6d 2d 72 65 61 6c  or "(random-real
0550: 29 20 72 65 74 75 72 6e 65 64 20 69 6c 6c 65 67  ) returned illeg
0560: 61 6c 20 76 61 6c 75 65 22 20 78 29 29 29 29 0a  al value" x)))).
0570: 0a 28 64 65 66 69 6e 65 20 28 63 68 65 63 6b 2d  .(define (check-
0580: 62 61 73 69 63 73 2d 31 29 0a 0a 20 20 3b 20 67  basics-1)..  ; g
0590: 65 6e 65 72 61 74 65 20 69 6e 63 72 65 61 73 69  enerate increasi
05a0: 6e 67 6c 79 20 6c 61 72 67 65 20 6e 75 6d 62 65  ngly large numbe
05b0: 72 73 0a 20 20 28 64 69 73 70 6c 61 79 20 22 3b  rs.  (display ";
05c0: 20 67 65 6e 65 72 61 74 69 6e 67 20 6c 61 72 67   generating larg
05d0: 65 20 6e 75 6d 62 65 72 73 20 5b 62 69 74 73 5d  e numbers [bits]
05e0: 3a 20 22 29 0a 20 20 28 64 6f 20 28 28 6b 20 30  : ").  (do ((k 0
05f0: 20 28 2b 20 6b 20 31 29 29 0a 20 20 20 20 20 20   (+ k 1)).      
0600: 20 28 6e 20 31 20 28 2a 20 6e 20 32 29 29 29 0a   (n 1 (* n 2))).
0610: 20 20 20 20 20 20 28 28 3e 20 6b 20 31 30 32 34        ((> k 1024
0620: 29 29 0a 20 20 20 20 28 64 69 73 70 6c 61 79 20  )).    (display 
0630: 6b 29 0a 20 20 20 20 28 64 69 73 70 6c 61 79 20  k).    (display 
0640: 22 20 22 29 0a 20 20 20 20 28 6d 79 2d 72 61 6e  " ").    (my-ran
0650: 64 6f 6d 2d 69 6e 74 65 67 65 72 20 6e 29 29 0a  dom-integer n)).
0660: 20 20 28 64 69 73 70 6c 61 79 20 22 6f 6b 22 29    (display "ok")
0670: 0a 20 20 28 6e 65 77 6c 69 6e 65 29 0a 0a 20 20  .  (newline)..  
0680: 3b 20 67 65 6e 65 72 61 74 65 20 73 6f 6d 65 20  ; generate some 
0690: 72 65 61 6c 73 0a 20 20 28 64 69 73 70 6c 61 79  reals.  (display
06a0: 20 22 3b 20 67 65 6e 65 72 61 74 69 6e 67 20 72   "; generating r
06b0: 65 61 6c 73 20 5b 31 30 30 30 20 74 69 6d 65 73  eals [1000 times
06c0: 5d 3a 20 22 29 0a 20 20 28 64 6f 20 28 28 6b 20  ]: ").  (do ((k 
06d0: 30 20 28 2b 20 6b 20 31 29 29 0a 20 20 20 20 20  0 (+ k 1)).     
06e0: 20 20 28 78 20 28 6d 79 2d 72 61 6e 64 6f 6d 2d    (x (my-random-
06f0: 72 65 61 6c 29 20 28 2b 20 78 20 28 6d 79 2d 72  real) (+ x (my-r
0700: 61 6e 64 6f 6d 2d 72 65 61 6c 29 29 29 29 0a 20  andom-real)))). 
0710: 20 20 20 20 20 28 28 3d 20 6b 20 31 30 30 30 29       ((= k 1000)
0720: 0a 20 20 20 20 20 20 20 78 29 29 0a 20 20 28 64  .       x)).  (d
0730: 69 73 70 6c 61 79 20 22 6f 6b 22 29 0a 20 20 28  isplay "ok").  (
0740: 6e 65 77 6c 69 6e 65 29 0a 0a 20 20 3b 20 67 65  newline)..  ; ge
0750: 74 2f 73 65 74 20 74 68 65 20 73 74 61 74 65 0a  t/set the state.
0760: 20 20 28 64 69 73 70 6c 61 79 20 22 3b 20 67 65    (display "; ge
0770: 74 2f 73 65 74 20 73 74 61 74 65 3a 20 22 29 0a  t/set state: ").
0780: 20 20 28 6c 65 74 2a 20 28 28 73 74 61 74 65 31    (let* ((state1
0790: 20 28 72 61 6e 64 6f 6d 2d 73 6f 75 72 63 65 2d   (random-source-
07a0: 73 74 61 74 65 2d 72 65 66 20 64 65 66 61 75 6c  state-ref defaul
07b0: 74 2d 72 61 6e 64 6f 6d 2d 73 6f 75 72 63 65 29  t-random-source)
07c0: 29 0a 20 20 20 20 20 20 20 20 20 28 78 31 20 28  ).         (x1 (
07d0: 6d 79 2d 72 61 6e 64 6f 6d 2d 69 6e 74 65 67 65  my-random-intege
07e0: 72 20 28 65 78 70 74 20 32 20 33 32 29 29 29 0a  r (expt 2 32))).
07f0: 20 20 20 20 20 20 20 20 20 28 73 74 61 74 65 32           (state2
0800: 20 28 72 61 6e 64 6f 6d 2d 73 6f 75 72 63 65 2d   (random-source-
0810: 73 74 61 74 65 2d 72 65 66 20 64 65 66 61 75 6c  state-ref defaul
0820: 74 2d 72 61 6e 64 6f 6d 2d 73 6f 75 72 63 65 29  t-random-source)
0830: 29 0a 20 20 20 20 20 20 20 20 20 28 78 32 20 28  ).         (x2 (
0840: 6d 79 2d 72 61 6e 64 6f 6d 2d 69 6e 74 65 67 65  my-random-intege
0850: 72 20 28 65 78 70 74 20 32 20 33 32 29 29 29 29  r (expt 2 32))))
0860: 0a 20 20 20 20 28 72 61 6e 64 6f 6d 2d 73 6f 75  .    (random-sou
0870: 72 63 65 2d 73 74 61 74 65 2d 73 65 74 21 20 64  rce-state-set! d
0880: 65 66 61 75 6c 74 2d 72 61 6e 64 6f 6d 2d 73 6f  efault-random-so
0890: 75 72 63 65 20 73 74 61 74 65 31 29 0a 20 20 20  urce state1).   
08a0: 20 28 6c 65 74 20 28 28 79 31 20 28 6d 79 2d 72   (let ((y1 (my-r
08b0: 61 6e 64 6f 6d 2d 69 6e 74 65 67 65 72 20 28 65  andom-integer (e
08c0: 78 70 74 20 32 20 33 32 29 29 29 29 0a 20 20 20  xpt 2 32)))).   
08d0: 20 20 20 28 69 66 20 28 6e 6f 74 20 28 3d 20 78     (if (not (= x
08e0: 31 20 79 31 29 29 0a 20 20 20 20 20 20 20 20 20  1 y1)).         
08f0: 20 28 65 72 72 6f 72 20 22 73 74 61 74 65 20 67   (error "state g
0900: 65 74 2f 73 65 74 20 64 6f 65 73 6e 27 74 20 77  et/set doesn't w
0910: 6f 72 6b 22 20 78 31 20 79 31 20 73 74 61 74 65  ork" x1 y1 state
0920: 31 29 29 29 0a 20 20 20 20 28 72 61 6e 64 6f 6d  1))).    (random
0930: 2d 73 6f 75 72 63 65 2d 73 74 61 74 65 2d 73 65  -source-state-se
0940: 74 21 20 64 65 66 61 75 6c 74 2d 72 61 6e 64 6f  t! default-rando
0950: 6d 2d 73 6f 75 72 63 65 20 73 74 61 74 65 32 29  m-source state2)
0960: 0a 20 20 20 20 28 6c 65 74 20 28 28 79 32 20 28  .    (let ((y2 (
0970: 6d 79 2d 72 61 6e 64 6f 6d 2d 69 6e 74 65 67 65  my-random-intege
0980: 72 20 28 65 78 70 74 20 32 20 33 32 29 29 29 29  r (expt 2 32))))
0990: 0a 20 20 20 20 20 20 28 69 66 20 28 6e 6f 74 20  .      (if (not 
09a0: 28 3d 20 78 32 20 79 32 29 29 0a 20 20 20 20 20  (= x2 y2)).     
09b0: 20 20 20 20 20 28 65 72 72 6f 72 20 22 73 74 61       (error "sta
09c0: 74 65 20 67 65 74 2f 73 65 74 20 64 6f 65 73 6e  te get/set doesn
09d0: 27 74 20 77 6f 72 6b 22 20 78 32 20 79 32 20 73  't work" x2 y2 s
09e0: 74 61 74 65 32 29 29 29 29 0a 20 20 28 64 69 73  tate2)))).  (dis
09f0: 70 6c 61 79 20 22 6f 6b 22 29 0a 20 20 28 6e 65  play "ok").  (ne
0a00: 77 6c 69 6e 65 29 0a 0a 20 20 3b 20 72 61 6e 64  wline)..  ; rand
0a10: 6f 6d 69 7a 65 21 0a 20 20 28 64 69 73 70 6c 61  omize!.  (displa
0a20: 79 20 22 3b 20 72 61 6e 64 6f 6d 69 7a 65 21 3a  y "; randomize!:
0a30: 20 22 29 0a 20 20 28 6c 65 74 2a 20 28 28 73 74   ").  (let* ((st
0a40: 61 74 65 31 20 28 72 61 6e 64 6f 6d 2d 73 6f 75  ate1 (random-sou
0a50: 72 63 65 2d 73 74 61 74 65 2d 72 65 66 20 64 65  rce-state-ref de
0a60: 66 61 75 6c 74 2d 72 61 6e 64 6f 6d 2d 73 6f 75  fault-random-sou
0a70: 72 63 65 29 29 0a 20 20 20 20 20 20 20 20 20 28  rce)).         (
0a80: 78 31 20 28 6d 79 2d 72 61 6e 64 6f 6d 2d 69 6e  x1 (my-random-in
0a90: 74 65 67 65 72 20 28 65 78 70 74 20 32 20 33 32  teger (expt 2 32
0aa0: 29 29 29 29 0a 20 20 20 20 28 72 61 6e 64 6f 6d  )))).    (random
0ab0: 2d 73 6f 75 72 63 65 2d 73 74 61 74 65 2d 73 65  -source-state-se
0ac0: 74 21 20 64 65 66 61 75 6c 74 2d 72 61 6e 64 6f  t! default-rando
0ad0: 6d 2d 73 6f 75 72 63 65 20 73 74 61 74 65 31 29  m-source state1)
0ae0: 0a 20 20 20 20 28 72 61 6e 64 6f 6d 2d 73 6f 75  .    (random-sou
0af0: 72 63 65 2d 72 61 6e 64 6f 6d 69 7a 65 21 20 64  rce-randomize! d
0b00: 65 66 61 75 6c 74 2d 72 61 6e 64 6f 6d 2d 73 6f  efault-random-so
0b10: 75 72 63 65 29 0a 20 20 20 20 28 6c 65 74 20 28  urce).    (let (
0b20: 28 79 31 20 28 6d 79 2d 72 61 6e 64 6f 6d 2d 69  (y1 (my-random-i
0b30: 6e 74 65 67 65 72 20 28 65 78 70 74 20 32 20 33  nteger (expt 2 3
0b40: 32 29 29 29 29 0a 20 20 20 20 20 20 28 69 66 20  2)))).      (if 
0b50: 28 3d 20 78 31 20 79 31 29 0a 20 20 20 20 20 20  (= x1 y1).      
0b60: 20 20 20 20 28 65 72 72 6f 72 20 22 72 61 6e 64      (error "rand
0b70: 6f 6d 2d 73 6f 75 72 63 65 2d 72 61 6e 64 6f 6d  om-source-random
0b80: 69 7a 65 21 20 64 69 64 6e 27 74 20 77 6f 72 6b  ize! didn't work
0b90: 22 20 78 31 20 73 74 61 74 65 31 29 29 29 29 0a  " x1 state1)))).
0ba0: 20 20 28 64 69 73 70 6c 61 79 20 22 6f 6b 22 29    (display "ok")
0bb0: 0a 20 20 28 6e 65 77 6c 69 6e 65 29 0a 0a 20 20  .  (newline)..  
0bc0: 3b 20 70 73 65 75 64 6f 2d 72 61 6e 64 6f 6d 69  ; pseudo-randomi
0bd0: 7a 65 21 0a 20 20 28 64 69 73 70 6c 61 79 20 22  ze!.  (display "
0be0: 3b 20 70 73 65 75 64 6f 2d 72 61 6e 64 6f 6d 69  ; pseudo-randomi
0bf0: 7a 65 21 3a 20 22 29 0a 20 20 28 6c 65 74 2a 20  ze!: ").  (let* 
0c00: 28 28 73 74 61 74 65 31 20 28 72 61 6e 64 6f 6d  ((state1 (random
0c10: 2d 73 6f 75 72 63 65 2d 73 74 61 74 65 2d 72 65  -source-state-re
0c20: 66 20 64 65 66 61 75 6c 74 2d 72 61 6e 64 6f 6d  f default-random
0c30: 2d 73 6f 75 72 63 65 29 29 0a 20 20 20 20 20 20  -source)).      
0c40: 20 20 20 28 78 31 20 28 6d 79 2d 72 61 6e 64 6f     (x1 (my-rando
0c50: 6d 2d 69 6e 74 65 67 65 72 20 28 65 78 70 74 20  m-integer (expt 
0c60: 32 20 33 32 29 29 29 29 0a 20 20 20 20 28 72 61  2 32)))).    (ra
0c70: 6e 64 6f 6d 2d 73 6f 75 72 63 65 2d 73 74 61 74  ndom-source-stat
0c80: 65 2d 73 65 74 21 20 64 65 66 61 75 6c 74 2d 72  e-set! default-r
0c90: 61 6e 64 6f 6d 2d 73 6f 75 72 63 65 20 73 74 61  andom-source sta
0ca0: 74 65 31 29 0a 20 20 20 20 28 72 61 6e 64 6f 6d  te1).    (random
0cb0: 2d 73 6f 75 72 63 65 2d 70 73 65 75 64 6f 2d 72  -source-pseudo-r
0cc0: 61 6e 64 6f 6d 69 7a 65 21 20 64 65 66 61 75 6c  andomize! defaul
0cd0: 74 2d 72 61 6e 64 6f 6d 2d 73 6f 75 72 63 65 20  t-random-source 
0ce0: 30 20 31 29 0a 20 20 20 20 28 6c 65 74 20 28 28  0 1).    (let ((
0cf0: 79 31 20 28 6d 79 2d 72 61 6e 64 6f 6d 2d 69 6e  y1 (my-random-in
0d00: 74 65 67 65 72 20 28 65 78 70 74 20 32 20 33 32  teger (expt 2 32
0d10: 29 29 29 29 0a 20 20 20 20 20 20 28 69 66 20 28  )))).      (if (
0d20: 3d 20 78 31 20 79 31 29 0a 20 20 20 20 20 20 20  = x1 y1).       
0d30: 20 20 20 28 65 72 72 6f 72 20 22 72 61 6e 64 6f     (error "rando
0d40: 6d 2d 73 6f 75 72 63 65 2d 70 73 65 75 64 6f 2d  m-source-pseudo-
0d50: 72 61 6e 64 6f 6d 69 7a 65 21 20 64 69 64 6e 27  randomize! didn'
0d60: 74 20 77 6f 72 6b 22 20 78 31 20 73 74 61 74 65  t work" x1 state
0d70: 31 29 29 29 0a 20 20 20 20 28 72 61 6e 64 6f 6d  1))).    (random
0d80: 2d 73 6f 75 72 63 65 2d 73 74 61 74 65 2d 73 65  -source-state-se
0d90: 74 21 20 64 65 66 61 75 6c 74 2d 72 61 6e 64 6f  t! default-rando
0da0: 6d 2d 73 6f 75 72 63 65 20 73 74 61 74 65 31 29  m-source state1)
0db0: 0a 20 20 20 20 28 72 61 6e 64 6f 6d 2d 73 6f 75  .    (random-sou
0dc0: 72 63 65 2d 70 73 65 75 64 6f 2d 72 61 6e 64 6f  rce-pseudo-rando
0dd0: 6d 69 7a 65 21 20 64 65 66 61 75 6c 74 2d 72 61  mize! default-ra
0de0: 6e 64 6f 6d 2d 73 6f 75 72 63 65 20 31 20 30 29  ndom-source 1 0)
0df0: 0a 20 20 20 20 28 6c 65 74 20 28 28 79 31 20 28  .    (let ((y1 (
0e00: 6d 79 2d 72 61 6e 64 6f 6d 2d 69 6e 74 65 67 65  my-random-intege
0e10: 72 20 28 65 78 70 74 20 32 20 33 32 29 29 29 29  r (expt 2 32))))
0e20: 0a 20 20 20 20 20 20 28 69 66 20 28 3d 20 78 31  .      (if (= x1
0e30: 20 79 31 29 0a 20 20 20 20 20 20 20 20 20 20 28   y1).          (
0e40: 65 72 72 6f 72 20 22 72 61 6e 64 6f 6d 2d 73 6f  error "random-so
0e50: 75 72 63 65 2d 70 73 65 75 64 6f 2d 72 61 6e 64  urce-pseudo-rand
0e60: 6f 6d 69 7a 65 21 20 64 69 64 6e 27 74 20 77 6f  omize! didn't wo
0e70: 72 6b 22 20 78 31 20 73 74 61 74 65 31 29 29 29  rk" x1 state1)))
0e80: 29 0a 20 20 28 64 69 73 70 6c 61 79 20 22 6f 6b  ).  (display "ok
0e90: 22 29 0a 20 20 28 6e 65 77 6c 69 6e 65 29 0a 20  ").  (newline). 
0ea0: 20 28 6e 65 77 6c 69 6e 65 29 29 0a 0a 0a 3b 20   (newline))...; 
0eb0: 54 65 73 74 69 6e 67 20 74 68 65 20 4d 52 47 33  Testing the MRG3
0ec0: 32 6b 33 61 20 47 65 6e 65 72 61 74 6f 72 20 28  2k3a Generator (
0ed0: 69 66 20 69 6d 70 6c 65 6d 65 6e 74 65 64 29 0a  if implemented).
0ee0: 3b 20 3d 3d 3d 3d 3d 3d 3d 3d 3d 3d 3d 3d 3d 3d  ; ==============
0ef0: 3d 3d 3d 3d 3d 3d 3d 3d 3d 3d 3d 3d 3d 3d 3d 3d  ================
0f00: 3d 3d 3d 3d 3d 3d 3d 3d 3d 3d 3d 3d 3d 3d 3d 3d  ================
0f10: 3d 0a 0a 3b 20 28 63 68 65 63 6b 2d 6d 72 67 33  =..; (check-mrg3
0f20: 32 6b 33 61 29 0a 3b 20 20 20 74 65 73 74 73 20  2k3a).;   tests 
0f30: 69 66 20 74 68 65 20 75 6e 64 65 72 6c 79 69 6e  if the underlyin
0f40: 67 20 67 65 6e 65 72 61 74 6f 72 20 69 73 20 74  g generator is t
0f50: 68 65 20 4d 52 47 33 32 6b 33 61 20 67 65 6e 65  he MRG32k3a gene
0f60: 72 61 74 6f 72 0a 3b 20 20 20 61 73 20 69 6d 70  rator.;   as imp
0f70: 6c 65 6d 65 6e 74 65 64 20 69 6e 20 74 68 65 20  lemented in the 
0f80: 72 65 66 65 72 65 6e 63 65 20 69 6d 70 6c 65 6d  reference implem
0f90: 65 6e 74 61 74 69 6f 6e 2e 20 54 68 69 73 20 66  entation. This f
0fa0: 75 6e 63 74 69 6f 6e 0a 3b 20 20 20 69 73 20 75  unction.;   is u
0fb0: 73 65 66 75 6c 20 74 6f 20 63 68 65 63 6b 20 77  seful to check w
0fc0: 68 65 74 68 65 72 20 74 68 65 20 72 65 66 65 72  hether the refer
0fd0: 65 6e 63 65 20 69 6d 70 6c 65 6d 65 6e 74 61 74  ence implementat
0fe0: 69 6f 6e 20 63 6f 6d 70 75 74 65 73 0a 3b 20 20  ion computes.;  
0ff0: 20 74 68 65 20 72 69 67 68 74 20 6e 75 6d 62 65   the right numbe
1000: 72 73 2e 0a 0a 28 64 65 66 69 6e 65 20 28 63 68  rs...(define (ch
1010: 65 63 6b 2d 6d 72 67 33 32 6b 33 61 29 0a 20 0a  eck-mrg32k3a). .
1020: 20 20 3b 20 63 68 65 63 6b 20 69 66 20 74 68 65    ; check if the
1030: 20 69 6e 69 74 69 61 6c 20 73 74 61 74 65 20 69   initial state i
1040: 73 20 41 5e 31 36 20 2a 20 28 31 20 30 20 30 20  s A^16 * (1 0 0 
1050: 31 20 30 20 30 29 0a 20 20 28 64 69 73 70 6c 61  1 0 0).  (displa
1060: 79 20 22 3b 20 63 68 65 63 6b 20 41 5e 31 36 20  y "; check A^16 
1070: 2a 20 28 31 20 30 20 30 20 31 20 30 20 30 29 22  * (1 0 0 1 0 0)"
1080: 29 0a 20 20 28 6c 65 74 2a 20 28 28 73 20 28 6d  ).  (let* ((s (m
1090: 61 6b 65 2d 72 61 6e 64 6f 6d 2d 73 6f 75 72 63  ake-random-sourc
10a0: 65 29 29 0a 20 20 20 20 20 20 20 20 20 28 73 74  e)).         (st
10b0: 61 74 65 31 20 28 72 61 6e 64 6f 6d 2d 73 6f 75  ate1 (random-sou
10c0: 72 63 65 2d 73 74 61 74 65 2d 72 65 66 20 73 29  rce-state-ref s)
10d0: 29 0a 09 20 28 72 61 6e 64 20 28 72 61 6e 64 6f  ).. (rand (rando
10e0: 6d 2d 73 6f 75 72 63 65 2d 6d 61 6b 65 2d 72 65  m-source-make-re
10f0: 61 6c 73 20 73 29 29 29 0a 20 20 20 20 28 72 61  als s))).    (ra
1100: 6e 64 6f 6d 2d 73 6f 75 72 63 65 2d 73 74 61 74  ndom-source-stat
1110: 65 2d 73 65 74 21 20 73 20 27 28 6c 65 63 75 79  e-set! s '(lecuy
1120: 65 72 2d 6d 72 67 33 32 6b 33 61 20 31 20 30 20  er-mrg32k3a 1 0 
1130: 30 20 31 20 30 20 30 29 29 0a 20 20 20 20 28 64  0 1 0 0)).    (d
1140: 6f 20 28 28 6b 20 30 20 28 2b 20 6b 20 31 29 29  o ((k 0 (+ k 1))
1150: 29 0a 09 28 28 3d 20 6b 20 31 36 29 0a 09 20 28  )..((= k 16).. (
1160: 6c 65 74 20 28 28 73 74 61 74 65 32 20 28 72 61  let ((state2 (ra
1170: 6e 64 6f 6d 2d 73 6f 75 72 63 65 2d 73 74 61 74  ndom-source-stat
1180: 65 2d 72 65 66 20 73 29 29 29 0a 09 20 20 20 28  e-ref s)))..   (
1190: 69 66 20 28 6e 6f 74 20 28 65 71 75 61 6c 3f 20  if (not (equal? 
11a0: 73 74 61 74 65 31 20 73 74 61 74 65 32 29 29 0a  state1 state2)).
11b0: 09 20 20 20 20 20 20 20 28 65 72 72 6f 72 20 22  .       (error "
11c0: 31 36 2d 74 68 20 73 74 61 74 65 20 61 66 74 65  16-th state afte
11d0: 72 20 28 31 20 30 20 30 20 31 20 30 20 30 29 20  r (1 0 0 1 0 0) 
11e0: 69 73 20 77 72 6f 6e 67 22 29 29 29 29 0a 09 28  is wrong"))))..(
11f0: 72 61 6e 64 29 29 29 0a 20 20 28 64 69 73 70 6c  rand))).  (displ
1200: 61 79 20 22 6f 6b 22 29 0a 20 20 28 6e 65 77 6c  ay "ok").  (newl
1210: 69 6e 65 29 0a 0a 20 20 3b 20 63 68 65 63 6b 20  ine)..  ; check 
1220: 69 66 20 70 73 65 75 64 6f 2d 72 61 6e 64 6f 6d  if pseudo-random
1230: 69 7a 65 21 20 61 64 76 61 6e 63 65 73 20 70 72  ize! advances pr
1240: 6f 70 65 72 6c 79 0a 20 20 28 64 69 73 70 6c 61  operly.  (displa
1250: 79 20 22 3b 20 63 68 65 63 6b 69 6e 67 20 28 72  y "; checking (r
1260: 61 6e 64 6f 6d 2d 73 6f 75 72 63 65 2d 70 73 65  andom-source-pse
1270: 75 64 6f 2d 72 61 6e 64 6f 6d 69 7a 65 21 20 73  udo-randomize! s
1280: 20 31 20 32 29 22 29 0a 20 20 28 6c 65 74 20 28   1 2)").  (let (
1290: 28 73 20 28 6d 61 6b 65 2d 72 61 6e 64 6f 6d 2d  (s (make-random-
12a0: 73 6f 75 72 63 65 29 29 29 0a 20 20 20 20 28 72  source))).    (r
12b0: 61 6e 64 6f 6d 2d 73 6f 75 72 63 65 2d 70 73 65  andom-source-pse
12c0: 75 64 6f 2d 72 61 6e 64 6f 6d 69 7a 65 21 20 73  udo-randomize! s
12d0: 20 31 20 32 29 0a 20 20 20 20 28 69 66 20 28 6e   1 2).    (if (n
12e0: 6f 74 20 28 65 71 75 61 6c 3f 20 28 72 61 6e 64  ot (equal? (rand
12f0: 6f 6d 2d 73 6f 75 72 63 65 2d 73 74 61 74 65 2d  om-source-state-
1300: 72 65 66 20 73 29 0a 09 09 20 20 20 20 20 27 28  ref s)...     '(
1310: 6c 65 63 75 79 65 72 2d 6d 72 67 33 32 6b 33 61  lecuyer-mrg32k3a
1320: 20 0a 09 09 20 20 20 20 20 20 20 31 32 35 30 38   ...       12508
1330: 32 36 31 35 39 20 0a 09 09 20 20 20 20 20 20 20  26159 ...       
1340: 33 30 30 34 33 35 37 34 32 33 20 0a 09 09 20 20  3004357423 ...  
1350: 20 20 20 20 20 20 34 33 31 33 37 33 35 36 33 20        431373563 
1360: 0a 09 09 20 20 20 20 20 20 20 33 33 32 32 35 32  ...       332252
1370: 36 38 36 34 20 0a 09 09 20 20 20 20 20 20 20 20  6864 ...        
1380: 36 32 33 33 30 37 33 37 38 20 0a 09 09 20 20 20  623307378 ...   
1390: 20 20 20 20 32 39 38 33 36 36 32 34 32 31 29 29      2983662421))
13a0: 29 0a 09 28 65 72 72 6f 72 20 22 70 73 65 75 64  )..(error "pseud
13b0: 6f 2d 72 61 6e 64 6f 6d 69 7a 65 21 20 67 69 76  o-randomize! giv
13c0: 65 73 20 77 72 6f 6e 67 20 72 65 73 75 6c 74 22  es wrong result"
13d0: 29 29 29 0a 20 20 28 64 69 73 70 6c 61 79 20 22  ))).  (display "
13e0: 6f 6b 22 29 0a 20 20 28 6e 65 77 6c 69 6e 65 29  ok").  (newline)
13f0: 0a 0a 20 20 3b 20 72 75 6e 20 74 68 65 20 63 68  ..  ; run the ch
1400: 65 63 6b 20 70 75 62 6c 69 73 68 65 64 20 62 79  eck published by
1410: 20 50 69 65 72 72 65 20 4c 27 45 63 75 79 65 72   Pierre L'Ecuyer
1420: 3a 0a 20 20 3b 20 20 20 4e 6f 74 65 20 74 68 61  :.  ;   Note tha
1430: 74 20 74 68 65 20 72 65 66 65 72 65 6e 63 65 20  t the reference 
1440: 69 6d 70 6c 65 6d 65 6e 74 61 74 69 6f 6e 20 64  implementation d
1450: 65 61 6c 73 20 73 6c 69 67 68 74 6c 79 20 64 69  eals slightly di
1460: 66 66 65 72 65 6e 74 0a 20 20 3b 20 20 20 77 69  fferent.  ;   wi
1470: 74 68 20 72 65 61 6c 73 20 6d 61 70 70 69 6e 67  th reals mapping
1480: 20 6d 31 2d 31 20 69 6e 74 6f 20 31 2d 31 2f 28   m1-1 into 1-1/(
1490: 6d 31 2b 31 29 20 61 6e 64 20 6e 6f 74 20 69 6e  m1+1) and not in
14a0: 74 6f 20 30 20 61 73 20 69 6e 0a 20 20 3b 20 20  to 0 as in.  ;  
14b0: 20 4c 27 45 63 75 79 65 72 27 73 20 6f 72 69 67   L'Ecuyer's orig
14c0: 69 6e 61 6c 20 70 72 6f 70 6f 73 61 6c 2e 20 48  inal proposal. H
14d0: 6f 77 65 76 65 72 2c 20 66 6f 72 20 74 68 65 20  owever, for the 
14e0: 66 69 72 73 74 20 31 30 5e 37 20 72 65 61 6c 73  first 10^7 reals
14f0: 0a 20 20 3b 20 20 20 74 68 61 74 20 6d 61 6b 65  .  ;   that make
1500: 73 20 6e 6f 20 64 69 66 66 65 72 65 6e 63 65 20  s no difference 
1510: 61 73 20 6d 31 2d 31 20 69 73 20 6e 6f 74 20 67  as m1-1 is not g
1520: 65 6e 65 72 61 74 65 64 2e 0a 20 20 28 64 69 73  enerated..  (dis
1530: 70 6c 61 79 20 22 3b 20 63 68 65 63 6b 69 6e 67  play "; checking
1540: 20 28 72 61 6e 64 6f 6d 2d 73 6f 75 72 63 65 2d   (random-source-
1550: 70 73 65 75 64 6f 2d 72 61 6e 64 6f 6d 69 7a 65  pseudo-randomize
1560: 21 20 73 20 31 20 32 29 2e 2e 2e 22 29 0a 20 20  ! s 1 2)...").  
1570: 28 6c 65 74 2a 20 28 28 78 20 30 2e 30 29 20 0a  (let* ((x 0.0) .
1580: 09 20 28 73 20 28 6d 61 6b 65 2d 72 61 6e 64 6f  . (s (make-rando
1590: 6d 2d 73 6f 75 72 63 65 29 29 0a 09 20 28 72 61  m-source)).. (ra
15a0: 6e 64 20 28 72 61 6e 64 6f 6d 2d 73 6f 75 72 63  nd (random-sourc
15b0: 65 2d 6d 61 6b 65 2d 72 65 61 6c 73 20 73 29 29  e-make-reals s))
15c0: 29 0a 20 20 20 20 28 72 61 6e 64 6f 6d 2d 73 6f  ).    (random-so
15d0: 75 72 63 65 2d 73 74 61 74 65 2d 73 65 74 21 0a  urce-state-set!.
15e0: 20 20 20 20 20 73 0a 20 20 20 20 20 27 28 6c 65       s.     '(le
15f0: 63 75 79 65 72 2d 6d 72 67 33 32 6b 33 61 20 31  cuyer-mrg32k3a 1
1600: 32 33 34 35 20 31 32 33 34 35 20 31 32 33 34 35  2345 12345 12345
1610: 20 31 32 33 34 35 20 31 32 33 34 35 20 31 32 33   12345 12345 123
1620: 34 35 29 29 0a 20 20 20 20 28 64 6f 20 28 28 6b  45)).    (do ((k
1630: 20 30 20 28 2b 20 6b 20 31 29 29 29 0a 09 28 28   0 (+ k 1)))..((
1640: 3d 20 6b 20 31 30 30 30 30 30 30 30 29 0a 09 20  = k 10000000).. 
1650: 28 69 66 20 28 6e 6f 74 20 28 3c 20 28 61 62 73  (if (not (< (abs
1660: 20 28 2d 20 78 20 35 30 30 31 30 39 30 2e 39 35   (- x 5001090.95
1670: 29 29 20 30 2e 30 31 29 29 0a 09 20 20 20 20 20  )) 0.01))..     
1680: 28 65 72 72 6f 72 20 22 62 61 64 20 73 75 6d 20  (error "bad sum 
1690: 6f 76 65 72 20 31 30 5e 37 20 72 65 61 6c 73 22  over 10^7 reals"
16a0: 20 78 29 29 29 0a 20 20 20 20 20 20 28 73 65 74   x))).      (set
16b0: 21 20 78 20 28 2b 20 78 20 28 72 61 6e 64 29 29  ! x (+ x (rand))
16c0: 29 29 29 0a 20 20 28 64 69 73 70 6c 61 79 20 22  ))).  (display "
16d0: 6f 6b 22 29 0a 20 20 28 6e 65 77 6c 69 6e 65 29  ok").  (newline)
16e0: 29 0a 0a 0a 3b 20 57 72 69 74 69 6e 67 20 44 61  )...; Writing Da
16f0: 74 61 20 74 6f 20 44 49 45 48 41 52 44 0a 3b 20  ta to DIEHARD.; 
1700: 3d 3d 3d 3d 3d 3d 3d 3d 3d 3d 3d 3d 3d 3d 3d 3d  ================
1710: 3d 3d 3d 3d 3d 3d 3d 0a 0a 3b 20 28 77 72 69 74  =======..; (writ
1720: 65 2d 64 69 65 68 61 72 64 20 66 69 6c 65 6e 61  e-diehard filena
1730: 6d 65 20 73 20 62 79 74 65 73 2d 70 65 72 2d 63  me s bytes-per-c
1740: 61 6c 6c 20 63 61 6c 6c 73 29 0a 3b 20 20 20 20  all calls).;    
1750: 63 72 65 61 74 65 73 20 61 20 62 69 6e 61 72 79  creates a binary
1760: 20 66 69 6c 65 20 74 6f 20 77 68 69 63 68 20 62   file to which b
1770: 79 74 65 73 2d 70 65 72 2d 63 61 6c 6c 20 2a 20  ytes-per-call * 
1780: 63 61 6c 6c 73 20 62 79 74 65 73 20 61 72 65 0a  calls bytes are.
1790: 3b 20 20 20 20 77 72 69 74 74 65 6e 2e 20 54 68  ;    written. Th
17a0: 65 20 62 79 74 65 73 20 61 72 65 20 6f 62 74 61  e bytes are obta
17b0: 69 6e 65 64 20 66 72 6f 6d 20 74 68 65 20 72 61  ined from the ra
17c0: 6e 64 6f 6d 20 73 6f 75 72 63 65 20 73 20 75 73  ndom source s us
17d0: 69 6e 67 0a 3b 20 20 20 20 74 68 65 20 72 61 6e  ing.;    the ran
17e0: 67 65 20 6e 20 3d 20 28 65 78 70 74 20 32 35 36  ge n = (expt 256
17f0: 20 62 79 74 65 73 2d 70 65 72 2d 63 61 6c 6c 29   bytes-per-call)
1800: 2e 0a 3b 20 20 20 20 20 20 20 54 68 65 20 69 6e  ..;       The in
1810: 74 65 6e 74 69 6f 6e 20 6f 66 20 77 72 69 74 65  tention of write
1820: 2d 64 69 65 68 61 72 64 20 69 73 20 74 6f 20 67  -diehard is to g
1830: 69 76 65 20 69 6d 70 6c 65 6d 65 6e 74 6f 72 73  ive implementors
1840: 20 61 20 0a 3b 20 20 20 20 27 31 35 20 6d 69 6e   a .;    '15 min
1850: 2e 27 2d 77 61 79 20 6f 66 20 72 75 6e 6e 69 6e  .'-way of runnin
1860: 67 20 74 68 65 69 72 20 66 61 76 6f 75 72 69 74  g their favourit
1870: 65 20 72 61 6e 64 6f 6d 20 6e 75 6d 62 65 72 20  e random number 
1880: 67 65 6e 65 72 61 74 6f 72 20 0a 3b 20 20 20 20  generator .;    
1890: 74 68 72 6f 75 67 68 20 61 20 70 72 65 74 74 79  through a pretty
18a0: 20 74 6f 75 67 68 20 74 65 73 74 73 75 69 74 65   tough testsuite
18b0: 2e 0a 3b 0a 3b 20 20 20 20 74 72 79 3a 20 46 6f  ..;.;    try: Fo
18c0: 72 20 74 68 65 20 72 65 66 65 72 65 6e 63 65 20  r the reference 
18d0: 69 6d 70 6c 65 6d 65 6e 74 61 74 69 6f 6e 2c 20  implementation, 
18e0: 74 68 65 20 63 61 6c 6c 0a 3b 0a 3b 20 20 20 20  the call.;.;    
18f0: 20 20 20 28 77 72 69 74 65 2d 64 69 65 68 61 72     (write-diehar
1900: 64 20 22 6f 75 74 66 69 6c 65 22 20 28 6d 61 6b  d "outfile" (mak
1910: 65 2d 72 61 6e 64 6f 6d 2d 73 6f 75 72 63 65 29  e-random-source)
1920: 20 34 20 32 38 36 37 32 30 30 29 0a 3b 0a 3b 20   4 2867200).;.; 
1930: 20 20 20 73 68 6f 75 6c 64 20 63 72 65 61 74 65     should create
1940: 20 61 20 66 69 6c 65 20 74 68 61 74 20 6c 6f 6f   a file that loo
1950: 6b 73 20 61 73 20 66 6f 6c 6c 6f 77 73 20 28 6f  ks as follows (o
1960: 64 20 2d 41 20 78 20 2d 74 20 78 31 20 6f 75 74  d -A x -t x1 out
1970: 66 69 6c 65 29 3a 0a 3b 0a 3b 20 20 20 20 20 20  file):.;.;      
1980: 20 30 30 30 30 30 30 30 20 39 32 20 62 62 20 37   0000000 92 bb 7
1990: 65 20 64 62 20 31 62 20 31 34 20 66 36 20 62 62  e db 1b 14 f6 bb
19a0: 20 62 62 20 35 34 20 61 31 20 35 35 20 63 32 20   bb 54 a1 55 c2 
19b0: 33 65 20 63 64 20 63 61 0a 3b 20 20 20 20 20 20  3e cd ca.;      
19c0: 20 30 30 30 30 30 31 30 20 32 33 20 30 31 20 32   0000010 23 01 2
19d0: 30 20 33 35 20 30 36 20 34 37 20 36 35 20 62 30  0 35 06 47 65 b0
19e0: 20 35 32 20 34 63 20 62 38 20 63 30 20 32 31 20   52 4c b8 c0 21 
19f0: 34 38 20 61 66 20 36 37 0a 3b 20 20 20 20 20 20  48 af 67.;      
1a00: 20 30 30 30 30 30 32 30 20 36 33 20 61 39 20 38   0000020 63 a9 8
1a10: 63 20 37 38 20 35 30 20 37 33 20 32 39 20 30 38  c 78 50 73 29 08
1a20: 20 36 32 20 64 31 20 32 32 20 37 66 20 61 36 20   62 d1 22 7f a6 
1a30: 38 39 20 39 36 20 37 37 0a 3b 20 20 20 20 20 20  89 96 77.;      
1a40: 20 30 30 30 30 30 33 30 20 39 38 20 32 38 20 36   0000030 98 28 6
1a50: 35 20 32 64 20 32 64 20 38 62 20 66 39 20 35 32  5 2d 2d 8b f9 52
1a60: 20 34 31 20 62 65 20 38 65 20 33 66 20 63 35 20   41 be 8e 3f c5 
1a70: 38 34 20 30 66 20 63 61 0a 3b 20 20 20 20 20 20  84 0f ca.;      
1a80: 20 30 30 30 30 30 34 30 20 63 30 20 66 61 20 30   0000040 c0 fa 0
1a90: 33 20 64 36 20 66 30 20 36 35 20 39 64 20 33 61  3 d6 f0 65 9d 3a
1aa0: 20 39 62 20 61 62 20 36 66 20 66 65 20 64 31 20   9b ab 6f fe d1 
1ab0: 61 61 20 35 66 20 39 32 0a 3b 20 20 20 20 20 20  aa 5f 92.;      
1ac0: 20 30 30 30 30 30 35 30 20 30 66 20 65 61 20 66   0000050 0f ea f
1ad0: 36 20 33 62 20 37 38 20 62 39 20 66 65 20 61 64  6 3b 78 b9 fe ad
1ae0: 20 36 33 20 35 65 20 34 39 20 66 31 20 39 64 20   63 5e 49 f1 9d 
1af0: 63 39 20 38 65 20 32 66 0a 3b 20 20 20 20 20 20  c9 8e 2f.;      
1b00: 20 30 30 30 30 30 36 30 20 35 33 20 61 39 20 35   0000060 53 a9 5
1b10: 64 20 33 32 20 64 34 20 32 30 20 35 31 20 31 64  d 32 d4 20 51 1d
1b20: 20 31 63 20 32 65 20 38 32 20 66 30 20 38 62 20   1c 2e 82 f0 8b 
1b30: 32 36 20 34 30 20 63 30 0a 3b 20 20 20 20 20 20  26 40 c0.;      
1b40: 20 2e 2e 2e 74 6f 74 61 6c 20 6c 65 6e 67 74 68   ...total length
1b50: 20 69 73 20 31 31 34 36 38 38 30 30 20 62 79 74   is 11468800 byt
1b60: 65 73 2e 0a 3b 0a 3b 20 20 20 20 54 68 65 20 6d  es..;.;    The m
1b70: 65 73 73 61 67 65 20 64 69 67 65 73 74 20 69 73  essage digest is
1b80: 20 6d 64 35 73 75 6d 20 3d 20 34 64 66 35 35 34   md5sum = 4df554
1b90: 66 35 36 63 62 35 65 64 32 35 31 62 64 30 34 62  f56cb5ed251bd04b
1ba0: 30 64 35 30 37 36 37 34 34 33 2e 0a 3b 0a 3b 20  0d50767443..;.; 
1bb0: 20 20 20 74 72 79 3a 20 46 6f 72 20 74 68 65 20     try: For the 
1bc0: 72 65 66 65 72 65 6e 63 65 20 69 6d 70 6c 65 6d  reference implem
1bd0: 65 6e 74 61 74 69 6f 6e 2c 20 74 68 65 20 63 61  entation, the ca
1be0: 6c 6c 0a 3b 0a 3b 20 20 20 20 20 20 20 28 77 72  ll.;.;       (wr
1bf0: 69 74 65 2d 64 69 65 68 61 72 64 20 22 6f 75 74  ite-diehard "out
1c00: 66 69 6c 65 22 20 28 6d 61 6b 65 2d 72 61 6e 64  file" (make-rand
1c10: 6f 6d 2d 73 6f 75 72 63 65 29 20 33 20 33 38 32  om-source) 3 382
1c20: 32 39 33 34 29 0a 3b 0a 3b 20 20 20 20 73 68 6f  2934).;.;    sho
1c30: 75 6c 64 20 63 72 65 61 74 65 20 61 20 66 69 6c  uld create a fil
1c40: 65 20 74 68 61 74 20 6c 6f 6f 6b 73 20 61 73 20  e that looks as 
1c50: 66 6f 6c 6c 6f 77 73 20 28 6f 64 20 2d 41 20 78  follows (od -A x
1c60: 20 2d 74 20 78 31 20 6f 75 74 66 69 6c 65 29 3a   -t x1 outfile):
1c70: 0a 3b 0a 3b 20 20 20 20 20 20 20 30 30 30 30 30  .;.;       00000
1c80: 30 20 62 62 20 37 65 20 64 62 20 33 30 20 61 33  0 bb 7e db 30 a3
1c90: 20 34 39 20 31 34 20 66 36 20 62 62 20 64 30 20   49 14 f6 bb d0 
1ca0: 66 32 20 64 30 20 35 34 20 61 31 20 35 35 20 38  f2 d0 54 a1 55 8
1cb0: 62 0a 3b 20 20 20 20 20 20 20 30 30 30 30 31 30  b.;       000010
1cc0: 20 38 63 20 30 33 20 33 65 20 63 64 20 63 61 20   8c 03 3e cd ca 
1cd0: 61 33 20 38 38 20 31 64 20 30 31 20 32 30 20 33  a3 88 1d 01 20 3
1ce0: 35 20 65 38 20 35 30 20 63 38 20 34 37 20 36 35  5 e8 50 c8 47 65
1cf0: 0a 3b 20 20 20 20 20 20 20 30 30 30 30 32 30 20  .;       000020 
1d00: 62 30 20 65 37 20 64 39 20 32 38 20 34 63 20 62  b0 e7 d9 28 4c b
1d10: 38 20 63 30 20 66 32 20 38 32 20 33 35 20 34 38  8 c0 f2 82 35 48
1d20: 20 61 66 20 36 37 20 34 32 20 33 65 20 38 61 0a   af 67 42 3e 8a.
1d30: 3b 20 20 20 20 20 20 20 30 30 30 30 33 30 20 61  ;       000030 a
1d40: 39 20 38 63 20 37 38 20 31 32 20 65 66 20 62 36  9 8c 78 12 ef b6
1d50: 20 37 33 20 32 39 20 30 38 20 66 66 20 65 39 20   73 29 08 ff e9 
1d60: 37 31 20 64 31 20 32 32 20 37 66 20 35 32 0a 3b  71 d1 22 7f 52.;
1d70: 20 20 20 20 20 20 20 30 30 30 30 34 30 20 62 38         000040 b8
1d80: 20 66 30 20 38 39 20 39 36 20 37 37 20 64 63 20   f0 89 96 77 dc 
1d90: 37 31 20 38 36 20 32 38 20 36 35 20 32 64 20 63  71 86 28 65 2d c
1da0: 32 20 38 32 20 66 63 20 38 62 20 66 39 0a 3b 20  2 82 fc 8b f9.; 
1db0: 20 20 20 20 20 20 30 30 30 30 35 30 20 35 32 20        000050 52 
1dc0: 64 37 20 32 33 20 32 61 20 62 65 20 38 65 20 33  d7 23 2a be 8e 3
1dd0: 66 20 36 31 20 61 38 20 39 39 20 38 34 20 30 66  f 61 a8 99 84 0f
1de0: 20 63 61 20 34 34 20 38 33 20 36 35 0a 3b 20 20   ca 44 83 65.;  
1df0: 20 20 20 20 20 30 30 30 30 36 30 20 66 61 20 30       000060 fa 0
1e00: 33 20 64 36 20 63 32 20 31 31 20 63 30 20 36 35  3 d6 c2 11 c0 65
1e10: 20 39 64 20 33 61 20 63 32 20 37 61 20 64 64 20   9d 3a c2 7a dd 
1e20: 61 62 20 36 66 20 66 65 20 31 63 0a 3b 20 20 20  ab 6f fe 1c.;   
1e30: 20 20 20 20 2e 2e 2e 74 6f 74 61 6c 20 6c 65 6e      ...total len
1e40: 67 74 68 20 69 73 20 31 31 34 36 38 38 30 32 20  gth is 11468802 
1e50: 62 79 74 65 73 2e 0a 3b 0a 3b 20 20 20 20 54 68  bytes..;.;    Th
1e60: 65 20 6d 65 73 73 61 67 65 20 64 69 67 65 73 74  e message digest
1e70: 20 69 73 20 6d 64 35 73 75 6d 20 3d 20 37 35 30   is md5sum = 750
1e80: 61 63 32 31 39 66 66 34 30 63 35 30 62 62 32 64  ac219ff40c50bb2d
1e90: 30 34 66 66 35 65 66 66 39 62 32 34 63 2e 0a 0a  04ff5eff9b24c...
1ea0: 28 64 65 66 69 6e 65 20 28 77 72 69 74 65 2d 64  (define (write-d
1eb0: 69 65 68 61 72 64 20 66 69 6c 65 6e 61 6d 65 20  iehard filename 
1ec0: 73 20 62 79 74 65 73 2d 70 65 72 2d 63 61 6c 6c  s bytes-per-call
1ed0: 20 63 61 6c 6c 73 29 0a 20 20 28 6c 65 74 20 28   calls).  (let (
1ee0: 28 70 6f 72 74 20 28 6f 70 65 6e 2d 6f 75 74 70  (port (open-outp
1ef0: 75 74 2d 66 69 6c 65 20 66 69 6c 65 6e 61 6d 65  ut-file filename
1f00: 29 29 0a 20 20 20 20 20 20 20 20 28 72 61 6e 64  )).        (rand
1f10: 20 28 72 61 6e 64 6f 6d 2d 73 6f 75 72 63 65 2d   (random-source-
1f20: 6d 61 6b 65 2d 69 6e 74 65 67 65 72 73 20 73 29  make-integers s)
1f30: 29 0a 20 20 20 20 20 20 20 20 28 6e 20 28 65 78  ).        (n (ex
1f40: 70 74 20 32 35 36 20 62 79 74 65 73 2d 70 65 72  pt 256 bytes-per
1f50: 2d 63 61 6c 6c 29 29 29 0a 20 20 20 20 28 64 6f  -call))).    (do
1f60: 20 28 28 69 20 30 20 28 2b 20 69 20 31 29 29 29   ((i 0 (+ i 1)))
1f70: 0a 20 20 20 20 20 20 20 20 28 28 3d 20 69 20 63  .        ((= i c
1f80: 61 6c 6c 73 29 0a 20 20 20 20 20 20 20 20 20 28  alls).         (
1f90: 63 6c 6f 73 65 2d 6f 75 74 70 75 74 2d 70 6f 72  close-output-por
1fa0: 74 20 70 6f 72 74 29 29 0a 20 20 20 20 20 20 28  t port)).      (
1fb0: 6c 65 74 20 28 28 78 20 28 72 61 6e 64 20 6e 29  let ((x (rand n)
1fc0: 29 29 0a 20 20 20 20 20 20 20 20 28 64 6f 20 28  )).        (do (
1fd0: 28 6b 20 30 20 28 2b 20 6b 20 31 29 29 29 20 28  (k 0 (+ k 1))) (
1fe0: 28 3d 20 6b 20 62 79 74 65 73 2d 70 65 72 2d 63  (= k bytes-per-c
1ff0: 61 6c 6c 29 29 0a 20 20 20 20 20 20 20 20 20 20  all)).          
2000: 28 70 75 74 2d 75 38 20 70 6f 72 74 20 28 6d 6f  (put-u8 port (mo
2010: 64 75 6c 6f 20 78 20 32 35 36 29 29 0a 20 20 20  dulo x 256)).   
2020: 20 20 20 20 20 20 20 28 73 65 74 21 20 78 20 28         (set! x (
2030: 71 75 6f 74 69 65 6e 74 20 78 20 32 35 36 29 29  quotient x 256))
2040: 29 29 29 29 29 0a 0a 3b 20 72 75 6e 20 73 6f 6d  )))))..; run som
2050: 65 20 74 65 73 74 73 0a 28 63 68 65 63 6b 2d 62  e tests.(check-b
2060: 61 73 69 63 73 2d 31 29 0a 28 64 69 73 70 6c 61  asics-1).(displa
2070: 79 20 22 70 61 73 73 65 64 20 28 63 68 65 63 6b  y "passed (check
2080: 2d 62 61 73 69 63 73 2d 31 29 22 29 0a 28 6e 65  -basics-1)").(ne
2090: 77 6c 69 6e 65 29 0a 0a 28 63 68 65 63 6b 2d 6d  wline)..(check-m
20a0: 72 67 33 32 6b 33 61 29 0a 28 64 69 73 70 6c 61  rg32k3a).(displa
20b0: 79 20 22 70 61 73 73 65 64 20 28 63 68 65 63 6b  y "passed (check
20c0: 2d 6d 72 67 33 32 6b 33 61 29 22 29 0a 28 6e 65  -mrg32k3a)").(ne
20d0: 77 6c 69 6e 65 29 0a 0a 3b 20 28 64 69 73 70 6c  wline)..; (displ
20e0: 61 79 20 22 47 65 6e 65 72 61 74 69 6e 67 20 64  ay "Generating d
20f0: 69 65 68 61 72 64 31 20 77 69 74 68 20 65 78 70  iehard1 with exp
2100: 65 63 74 65 64 20 4d 44 35 3d 34 64 66 35 35 34  ected MD5=4df554
2110: 66 35 36 63 62 35 65 64 32 35 31 62 64 30 34 62  f56cb5ed251bd04b
2120: 30 64 35 30 37 36 37 34 34 33 5c 6e 22 29 0a 3b  0d50767443\n").;
2130: 20 28 77 72 69 74 65 2d 64 69 65 68 61 72 64 20   (write-diehard 
2140: 22 64 69 65 68 61 72 64 31 22 20 28 6d 61 6b 65  "diehard1" (make
2150: 2d 72 61 6e 64 6f 6d 2d 73 6f 75 72 63 65 29 20  -random-source) 
2160: 34 20 32 38 36 37 32 30 30 29 0a 0a 3b 28 64 69  4 2867200)..;(di
2170: 73 70 6c 61 79 20 22 47 65 6e 65 72 61 74 69 6e  splay "Generatin
2180: 67 20 64 69 65 68 61 72 64 32 20 77 69 74 68 20  g diehard2 with 
2190: 65 78 70 65 63 74 65 64 20 4d 44 35 3d 37 35 30  expected MD5=750
21a0: 61 63 32 31 39 66 66 34 30 63 35 30 62 62 32 64  ac219ff40c50bb2d
21b0: 30 34 66 66 35 65 66 66 39 62 32 34 63 5c 6e 22  04ff5eff9b24c\n"
21c0: 29 0a 3b 20 28 64 69 73 70 6c 61 79 20 22 47 65  ).; (display "Ge
21d0: 6e 65 72 61 74 69 6e 67 20 64 69 65 68 61 72 64  nerating diehard
21e0: 32 20 77 69 74 68 20 65 78 70 65 63 74 65 64 20  2 with expected 
21f0: 4d 44 35 3d 39 63 34 63 62 31 66 36 32 35 31 65  MD5=9c4cb1f6251e
2200: 66 61 33 30 31 61 39 38 66 32 32 36 61 37 36 64  fa301a98f226a76d
2210: 65 35 62 39 22 29 0a 3b 20 28 77 72 69 74 65 2d  e5b9").; (write-
2220: 64 69 65 68 61 72 64 20 22 64 69 65 68 61 72 64  diehard "diehard
2230: 32 22 20 28 6d 61 6b 65 2d 72 61 6e 64 6f 6d 2d  2" (make-random-
2240: 73 6f 75 72 63 65 29 20 33 20 33 38 32 32 39 33  source) 3 382293
2250: 34 29 20 0a                                      4) .