In my post on this subject on another thread
http://www.ofpec.com/yabbse/index.php?board=8;action=display;threadid=25189I suggested that one way to select random points within a rectangle centred on (X,Y) was to use:
_Xcoord = X - _Xrange + 2*random _Xrange
_Ycoord = Y - _Yrange + 2*random _Yrange
and for a circle I suggested:
_angle = random 360
_dist = random _radius
_Xcoord = X + _dist*sin(angle)
_Ycoord = Y + _dist*cos(angle)
I have been reflecting on this and the results of those reflections are:
(In all that follows I assume OFP has a good random number generator)
In the above formulae for a rectangle the probability of any one small part of the rectangle being selected is the same as for any other similar sized part of the rectangle. In other words the probability of selection is spread evenly across the rectangle.
For the circle the probability is not evenly spread, it is concentrated in the centre of the circle. This is fine if you are simulating the inaccuracy of an artillery shell say, but sometimes this may not be what you want. (If you are not sure why the probabilities are concentrated in the centre then please read the footnote below.)
If you want to select a random point in a circle and you would like the probability of selection to be spread evenly across the circle then the way to do this is:
_angle = random 360
_dist = _radius *(random 1)^0.5
_Xcoord = X + _dist*sin(angle)
_Ycoord = Y + _dist*cos(angle)
This is approximate, but is good enough.
Footnote: If _dist is selected at random why do the probabilities concentrate in the centre of a circle?
Imagine a ring of inner radius D and outer radius D+1. The probability of a random point being selected that lies on the ring is independent of D (in fact it is 1/_radius).
But the area of that ring = Pi*(D+1)^2 - Pi*D^2
= Pi*(2*D + 1)
So although the probability of selecting a point on the ring is independent of D the area over which these points are to be spread increases as D increases. So that close to the centre of the circle the points are selected more densely than they are further from the centre.
Just a thought.