Statistics/Basic: Difference between revisions
Content deleted Content added
m Forgot explanation |
No edit summary |
||
Line 450: | Line 450: | ||
This could handle a trillion random numbers on a bog-standard computer, but I am not inclined to wait that long. |
This could handle a trillion random numbers on a bog-standard computer, but I am not inclined to wait that long. |
||
=={{header|Liberty BASIC}}== |
|||
Be aware that the PRNG in LB has a SLIGHT bias. |
|||
<lang lb> |
|||
call sample 100 |
|||
call sample 1000 |
|||
call sample 10000 |
|||
end |
|||
sub sample n |
|||
dim dat( n) |
|||
for i =1 to n |
|||
dat( i) =rnd( 1) |
|||
next i |
|||
'// show mean, standard deviation |
|||
sum =0 |
|||
sSq =0 |
|||
for i =1 to n |
|||
sum =sum +dat( i) |
|||
sSq =sSq +dat( i)^2 |
|||
next i |
|||
print n; " data terms used." |
|||
mean =sum / n |
|||
print "Mean ="; mean |
|||
print "Stddev ="; ( sSq /n -mean^2)^0.5 |
|||
'// show histogram |
|||
nBins =10 |
|||
dim bins( nBins) |
|||
for i =1 to n |
|||
z =int( nBins *dat( i)) |
|||
bins( z) =bins( z) +1 |
|||
next i |
|||
for b =0 to nBins -1 |
|||
for j =1 to int( nBins *bins( b)) /n *70) |
|||
print "#"; |
|||
next j |
|||
print |
|||
next b |
|||
print |
|||
end sub |
|||
</lang> |
|||
100000 data terms used. |
|||
Mean =0.49870232 |
|||
Stddev =0.28926563 |
|||
###################################################################### |
|||
###################################################################### |
|||
###################################################################### |
|||
###################################################################### |
|||
##################################################################### |
|||
##################################################################### |
|||
##################################################################### |
|||
##################################################################### |
|||
###################################################################### |
|||
##################################################################### |
|||
=={{header|PARI/GP}}== |
=={{header|PARI/GP}}== |