55 lines
1.5 KiB
Plaintext
55 lines
1.5 KiB
Plaintext
HIMEM = PAGE + 20000000
|
|
|
|
PRINT "Single run samples for n = 3:"
|
|
SofN% = FNs_of_n_creator(3)
|
|
FOR I% = 0 TO 9
|
|
!^a%() = FN(SofN%)(I%)
|
|
PRINT " For item " ; I% " sample(s) = " FNshowarray(a%(), I%+1)
|
|
NEXT
|
|
|
|
DIM cnt%(9)
|
|
PRINT '"Digit counts after 100000 runs:"
|
|
FOR rep% = 1 TO 100000
|
|
IF (rep% MOD 1000) = 0 PRINT ; rep% ; CHR$(13) ;
|
|
F% = FNs_of_n_creator(3)
|
|
FOR I% = 0 TO 9
|
|
!^a%() = FN(F%)(I%)
|
|
NEXT
|
|
cnt%(a%(1)) += 1 : cnt%(a%(2)) += 1 : cnt%(a%(3)) += 1
|
|
NEXT
|
|
FOR digit% = 0 TO 9
|
|
PRINT " " ; digit% " : " ; cnt%(digit%)
|
|
NEXT
|
|
END
|
|
|
|
REM Dynamically creates this function:
|
|
REM DEF FNfunction(item%) : PRIVATE samples%(), index%
|
|
REM DIM samples%(n%) : = FNs_of_n(item%, samples%(), index%)
|
|
DEF FNs_of_n_creator(n%)
|
|
LOCAL p%, f$
|
|
f$ = "(item%) : " + CHR$&0E + " samples%(), index% : " + \
|
|
\ CHR$&DE + " samples%(" + STR$(n%) + ") : = " + \
|
|
\ CHR$&A4 + "s_of_n(item%, samples%(), index%)"
|
|
DIM p% LEN(f$) + 4 : $(p%+4) = f$ : !p% = p%+4
|
|
= p%
|
|
|
|
DEF FNs_of_n(D%, s%(), RETURN I%)
|
|
LOCAL N%
|
|
N% = DIM(s%(),1)
|
|
I% += 1
|
|
IF I% <= N% THEN
|
|
s%(I%) = D%
|
|
ELSE
|
|
IF RND(I%) <= N% s%(RND(N%)) = D%
|
|
ENDIF
|
|
= !^s%()
|
|
|
|
DEF FNshowarray(a%(), n%)
|
|
LOCAL i%, a$
|
|
a$ = "["
|
|
IF n% > DIM(a%(),1) n% = DIM(a%(),1)
|
|
FOR i% = 1 TO n%
|
|
a$ += STR$(a%(i%)) + ", "
|
|
NEXT
|
|
= LEFT$(LEFT$(a$)) + "]"
|