37 lines
744 B
Plaintext
37 lines
744 B
Plaintext
MAXN = 20
|
|
TIMES = 10000'00
|
|
|
|
't0=time$("ms")
|
|
FOR n = 1 TO MAXN
|
|
avg = FNtest(n, TIMES)
|
|
theory = FNanalytical(n)
|
|
diff = (avg / theory - 1) * 100
|
|
PRINT n, avg, theory, using("##.####",diff); "%"
|
|
NEXT
|
|
't1=time$("ms")
|
|
'print t1-t0; " ms"
|
|
END
|
|
|
|
function FNanalytical(n)
|
|
FOR i = 1 TO n
|
|
s = s+ FNfactorial(n) / n^i / FNfactorial(n-i)
|
|
NEXT
|
|
FNanalytical = s
|
|
end function
|
|
|
|
function FNtest(n, times)
|
|
FOR i = 1 TO times
|
|
x = 1 : b = 0
|
|
WHILE (b AND x) = 0
|
|
c = c + 1
|
|
b = b OR x
|
|
x = 2^int(n*RND(1))
|
|
WEND
|
|
NEXT
|
|
FNtest = c / times
|
|
end function
|
|
|
|
function FNfactorial(n)
|
|
IF n=1 OR n=0 THEN FNfactorial=1 ELSE FNfactorial= n * FNfactorial(n-1)
|
|
end function
|