43 lines
755 B
Plaintext
43 lines
755 B
Plaintext
call sample 100
|
|
call sample 1000
|
|
call sample 10000
|
|
|
|
end
|
|
|
|
sub sample n
|
|
dim samp(n)
|
|
for i =1 to n
|
|
samp(i) =rnd(1)
|
|
next i
|
|
|
|
' calculate mean, standard deviation
|
|
sum = 0
|
|
sumSq = 0
|
|
for i = 1 to n
|
|
sum = sum + samp(i)
|
|
sumSq = sumSq + samp(i)^2
|
|
next i
|
|
print n; " Samples used."
|
|
|
|
mean = sum / n
|
|
print "Mean = "; mean
|
|
|
|
print "Std Dev = "; (sumSq /n -mean^2)^0.5
|
|
|
|
'------- Show histogram
|
|
bins = 10
|
|
dim bins(bins)
|
|
for i = 1 to n
|
|
z = int(bins * samp(i))
|
|
bins(z) = bins(z) +1
|
|
next i
|
|
for b = 0 to bins -1
|
|
print b;" ";
|
|
for j = 1 to int(bins *bins(b)) /n *70
|
|
print "*";
|
|
next j
|
|
print
|
|
next b
|
|
print
|
|
end sub
|