program define lott version 4.0 preserve clear gph open gph pen 1 quietly{ global ndraws=0 global npairs=0 global fract=0 set obs 50 gen x=(mod(_n-1,10)+1)/10 gen y=1-int((_n-1)/10)/5 gen str2 z=string(_n) gen xx=. gen yy=. gen x1=. gen y1=. gen str2 z1= string(_n) in 1/6} set graphics off graph y x, s(i) xlab(0,1) ylab(0,1) bbox(3000,0,23000,24000,850,400,0) set graphics on gphconv gph close gph open gph pen 1 global D_sm1 "# draws" global D_sm2 "# with pairs" global D_sm3 "Rel freq" wdctl static D_sm1 5 80 40 10 wdctl static ndraws 47 80 20 10 wdctl static D_sm2 5 95 40 10 wdctl static npairs 47 95 20 10 wdctl static D_sm3 5 110 40 10 wdctl static fract 47 110 20 10 wdctl button "Draw" 5 5 60 12 HJN_B1 wdctl button "Draw n Times" 5 20 60 12 HJN_B3 wdctl button "Help" 5 35 60 12 HJN_B5 wdctl button "Close" 5 50 60 12 HJN_B6 global D_sm4 "n" global HJN_V1=10 wdctl static D_sm4 5 65 20 12 wdctl edit HJN_V1 30 65 20 12 global HJN_B1 "lottdr 0" global HJN_B3 "lott10" global HJN_B5 "whelp lott" global HJN_B6 "lottdr 1" lottdr 0 noi wdlg "Lottery" 5 5 70 140 gph close restore end program define lott10 version 4.0 if $HJN_V1 < 1 | $HJN_V1 > 200 { sstopbox stop "Number of draws must be between 1 and 200" exit} local i=1 while `i'<=$HJN_V1 { lottdr 0 wdupdate local i=`i'+1} end program define lottdr version 4.0 local arg=`1' if `arg'==1 { replace x1=. replace x1=real(z1) sort x1 local i=1 while `i'<= 6 { local xval=(`i')/6. local zval=x1[`i'] drtext `xval' 0 0 `zval' local i=`i'+1} gph text 1000 16000 0 0 # of draws=$ndraws, # with pairs=$npairs, relative frequency=$fract exit 1234} gph close gph open gph pen 1 global ndraws=$ndraws+1 points2 x y 1000 1 texts x y z replace xx=uniform() replace yy=_n replace x1=. replace y1=. local i=1 while `i' <= 6 { * Get random integer, i1, in (1,50-i+1): local i5=50-`i'+1 local i1=int(`i5' * xx[`i'])+1 * Now trade yy[i1] with yy[i5]: local i3=yy[`i1'] replace yy=yy[`i5'] in `i1' replace yy=`i3' in `i5' replace x1=x[`i3'] in `i' replace y1=y[`i3'] in `i' replace z1=z[`i3'] in `i' local i=`i'+1} gph pen 3 points2 x1 y1 1000 1 texts x1 y1 z1 replace x1=. replace x1=real(z1) sort x1 local pairs=0 local i=1 while `i'<= 5 { local i1=`i'+1 if abs(x1[`i']-x1[`i1']) < 1.5 {local pairs=1} local i=`i'+1} if `pairs'==1 {global npairs=$npairs+1} global fract: display %5.3f $npairs/$ndraws gph text 2000 16000 0 0 Draw # $ndraws end exit