Three points are chosen randomly and independently on a circle.
Determine the probability that each of the three pairwise distances between the points is less than the radius of the circle.
The position on the circle is given in units of one circumference and is measured along the circumference. Therefore if the distance between two points is more than one half, its complement is taken. The distance along the arc must be under 1/6 circumference for the chord distance to be less than one radius.
DefDbl AZ
Dim crlf$, ptpos(3)
Function mform$(x, t$)
a$ = Format$(x, t$)
If Len(a$) < Len(t$) Then a$ = Space$(Len(t$)  Len(a$)) & a$
mform$ = a$
End Function
Private Sub Form_Load()
ChDir "C:\Program Files (x86)\DevStudio\VB\projects\flooble"
Text1.Text = ""
crlf$ = Chr(13) + Chr(10)
Form1.Visible = True
DoEvents
For trial = 1 To 12000
For pt = 1 To 3
ptpos(pt) = Rnd(1)
Next pt
good = 1
For pt1 = 1 To 2
For pt2 = pt1 + 1 To 3
dist = Abs(ptpos(pt1)  ptpos(pt2))
If dist > 0.5 Then dist = 1  dist
If dist > 1 / 6 Then good = 0: Exit For
Next
Next
If good Then goodct = goodct + 1
If trial Mod 120 = 0 Then
Text1.Text = Text1.Text & mform(goodct, "#######") & mform(trial, "########") & mform(goodct / trial, "##0.000000") & mform(trial / goodct, "###.0000") & crlf
DoEvents
Randomize Timer
End If
Next
Text1.Text = Text1.Text & crlf & "done"
End Sub
It finds, in one run:
939 12000 0.078250 12.7796
That is, the condition held in 939 out of 12,000 trials or 0.07825 of the time, or 1/12.7796.
Another run of the program:
1018 12000 0.084833 11.7878
and another:
998 12000 0.083167 12.0240

Posted by Charlie
on 20140807 13:29:43 