57 lines
1.1 KiB
Plaintext
57 lines
1.1 KiB
Plaintext
Procedure.f randomf()
|
|
#RNG_max_resolution = 2147483647
|
|
ProcedureReturn Random(#RNG_max_resolution) / #RNG_max_resolution
|
|
EndProcedure
|
|
|
|
Procedure sample(n)
|
|
Protected i, nBins, binNumber, tickMarks, maxBinValue
|
|
Protected.f sum, sumSq, mean
|
|
|
|
Dim dat.f(n)
|
|
For i = 1 To n
|
|
dat(i) = randomf()
|
|
Next
|
|
|
|
;show mean, standard deviation
|
|
For i = 1 To n
|
|
sum + dat(i)
|
|
sumSq + dat(i) * dat(i)
|
|
Next i
|
|
|
|
PrintN(Str(n) + " data terms used.")
|
|
mean = sum / n
|
|
PrintN("Mean =" + StrF(mean))
|
|
PrintN("Stddev =" + StrF((sumSq / n) - Sqr(mean * mean)))
|
|
|
|
;show histogram
|
|
nBins = 10
|
|
Dim bins(nBins)
|
|
For i = 1 To n
|
|
binNumber = Int(nBins * dat(i))
|
|
bins(binNumber) + 1
|
|
Next
|
|
|
|
maxBinValue = 1
|
|
For i = 0 To nBins
|
|
If bins(i) > maxBinValue
|
|
maxBinValue = bins(i)
|
|
EndIf
|
|
Next
|
|
|
|
#normalizedMaxValue = 70
|
|
For binNumber = 0 To nBins
|
|
tickMarks = Int(bins(binNumber) * #normalizedMaxValue / maxBinValue)
|
|
PrintN(ReplaceString(Space(tickMarks), " ", "#"))
|
|
Next
|
|
PrintN("")
|
|
EndProcedure
|
|
|
|
If OpenConsole()
|
|
sample(100)
|
|
sample(1000)
|
|
sample(10000)
|
|
|
|
Print(#CRLF$ + #CRLF$ + "Press ENTER to exit"): Input()
|
|
CloseConsole()
|
|
EndIf
|