01-25-2023, 05:37 PM
(This post was last modified: 01-25-2023, 06:44 PM by dcromley.
Edit Reason: need "as Long"
)
This reminded me of my "Bates distribution" program in my files, which I ported: (Very good in QB64.)
Code: (Select All)
_Title "Bates distribution" ' dcromley
' https://en.wikipedia.org/wiki/Bates_distribution
Option _Explicit
Screen _NewImage(1024, 768, 256)
Color 0, 15
Cls
Dim Shared n000 as Long, yfactor
Dim exp2
n000 = 10 ^ 6 ' big number
For exp2 = 0 To 3 ' for 1,2,4,8
Dim nrnds
nrnds = 2 ^ exp2 ' now 1,2,4,8
yfactor = 768 * 1024 / n000 / 5 ' height
doDist (nrnds) ' plot a distribution
Next exp2
Locate 37, 62: Print "1 rnd"
Locate 28, 62: Print "2 rnds"
Locate 21, 62: Print "4 rnds"
Locate 10, 62: Print "8 rnds"
While InKey$ = "": Wend: System
Sub doDist (nrnds) ' plot distribution
Dim i as Long, x, r, a(1023)
For i = 1 To n000 ' fill array with counts
r = Int(rand(nrnds) / nrnds * 1024) ' random number 0 to 1023
a(r) = a(r) + 1 ' count of hits
Next i
For x = 0 To 1022 ' plot array
Line (x, 767 - a(x) * yfactor)-(x + 1, 767 - a(x + 1) * yfactor)
Next x
End Sub
Function rand (kn) ' sum of kn random numbers 0 to 1
Dim i, ret
For i = 1 To kn
ret = ret + Rnd
Next i
rand = ret
End Function
___________________________________________________________________________________
I am mostly grateful for the people who came before me. Will the people after me be grateful for me?
I am mostly grateful for the people who came before me. Will the people after me be grateful for me?