Contesting for Idiot du Jour

Roger Guay irog at mac.com
Sat Sep 5 14:28:28 EDT 2020


Aha, in prepping my code to send to you, I found an error! Now the Cartesian Coord code is consistent with the Polar Coord code producing a ratio of about ⅓. Here is the code:

on mouseDown

	getStuff

end mouseDown


local tR, tX0, tY0, txl, tX1, tY1, tconstL, tTotCount, tL, tLongCount, tLocA, tLocB


on getStuff

	put item 1 of the loc of grc OuterCircle into tX0

	put item 2 of the loc of grc OuterCircle into tY0

	put the width of grc OuterCircle/2 into tR

	put the left of grc outerCircle into tXl

	put 2*tR*cos(Pi/6) into tconstL

	put "" into tTotCount

	put "" into tLongCount

	emptyFlds

end getStuff


on mouseUp

	lock screen

	repeat 10000

		add 1 to tTotCount

		PickApointA

		PickApointB

		set the points of grc theChord to tLocA, tLocB

		GetLength tLocA, tLocB

	end repeat

	put tTotCount into fld "totcountFld"

	put tLongCount/tTotCount into fld "RatioFld"

	unlock screen

end mouseUp


on PickApointA

	set the numberFormat to "#."

	put tXl + random(400) into X

	put sqrt(tR^2 - (X-tX0)^2) - tY0 into y

	get random(2)

	if it is 1 then put x, + y+2*tY0 into tLocA

	else put x, - y into tLocA

end PickApointA


on PickApointB

	set the numberFormat to "#."

	put tXl + random(400) into X

	put sqrt(tR^2 - (X-tX0)^2) - tY0 into y

	get random(2)

	if it is 1 then put x, + y+2*tY0 into tLocB

	else put x, - y into tLocB

end PickApointB


on GetLength pLocA, pLocB

	put item 1 of pLocA into PX1

	put item 2 of pLocA into Py1

	put item 1 of pLocB into PX2

	put item 2 of pLocB into Py2

	set the numberFormat to "#.0"

	put (pX2- pX1)^2 + (pY2- pY1)^2 into Lsquared

	put Sqrt(Lsquared) into tL

	if tL > tconstL then add 1 to tLongCount ---

	put tLongCount into fld "LongCountFld"

end GetLength


Thanks,
Roger


> On Sep 5, 2020, at 11:07 AM, Thomas von Fintel via use-livecode <use-livecode at lists.runrev.com> wrote:
> 
> „I am known for making many more mistakes than not!“
> Aren‘t we all?
> I guess using Cartesian coordinates for choosing points on a circle could produce some bias, though I have no clear idea how.
> So, what is your code?
> 
> Thomas
> 
>> Am 05.09.2020 um 19:15 schrieb Roger Guay via use-livecode <use-livecode at lists.runrev.com>:
>> 
>> I am known for making many more mistakes than not!
> 
> 
> _______________________________________________
> use-livecode mailing list
> use-livecode at lists.runrev.com
> Please visit this url to subscribe, unsubscribe and manage your subscription preferences:
> http://lists.runrev.com/mailman/listinfo/use-livecode




More information about the use-livecode mailing list