Contesting for Idiot du Jour
Roger Guay
irog at mac.com
Wed Sep 2 22:38:29 EDT 2020
Your chance to be Genius du Jour:
If I construct 2 concentric circles, one being half the radius of the larger, then simple math shows that the smaller circle has an area ¼ the area of the larger.
Now if I generate a random point within the radius of the larger circle, I should expect that the probability of it landing in the smaller circle to be ¼.
But, I must be doing something wrong because I get ½ !
Here is my script:
on mouseDown
getStuff
end mouseDown
local tR, tTheta, tX0, tY0, tX1, tY1, tTotCount, tL, tLongCount
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 "" into tTotCount
put "" into tLongCount
emptyFlds
end getStuff
on mouseUp
lock screen
repeat 1000
put random(200) into tR -- 200 is half the width of the larger circle
if tR > 1 then
## put random(2*pi) into tTheta1
get random(360)
put it*pi/180 into tTheta1
put tR*cos(tTheta1) into tX1
put tR*sin(tTheta1) into tY1
set the loc of grc Ptgrc to tX0 + tX1, tY0 - tY1 --- grc Ptgrc is a 2 pixle oval
if intersect(grc Ptgrc, grc InnerCircle, "opaque Pixels") then add 1 to tLongCount
add 1 to tTotCount
end if
end repeat
put tTotCount into fld "totcountFld"
put tLongCount into fld “LongCountFld"
put tLongCount/tTotCount into fld "RatioFld"
unlock screen
end mouseUp
Apparently, this does not generate a random point within the larger circle! Can someone please tell me what’s wrong here?
Thanks,
Roger
More information about the use-livecode
mailing list