if it's based on a grid of pixels
function getPossibleSpots(int s, int r) //find the pixels in 1/4 of square - circle, multiply by 4 and return
{
s = s / 2;
int area = s * s - s * r; //the vertical buffer room
int rr = r * r;
for(int i = 0; i < r; i++)
area += s - (int)Math.sqrt(rr - i * i);
return area * 4;
}
function decodeSpot(int s, int r, int spot)
{
s = s / 2;
int quadrant = spot % 4;
spot = spot >> 2;
int y = 0;
int rr = r * r;
for(int i = 0; i < s - r; i++)
if(spot < s)
return rotateSpot(s * 2, r, spot, y, quadrant);
else
{
spot -= s;
y++;
}
for(int i = r; i >= 0; i--)
if(spot < (int)Math.sqrt(rr - i * i))
return rotateSpot(s * 2, r, spot, y, quadrant);
else
{
spot -= (int)Math.sqrt(rr - i * i));
y++;
}
return rotateSpot(s * 2, r, spot, y, quadrant);
}
function rotateSpot(int s, int r, int x, int y, int quadrant)
{
if(quadrant | 1)
x = s - x;
if(quadrant | 2)
y = s - y;
return x SPC y;
}
function getRandomSpot(int s, int r)
{
return decodeSpot(s, r, (int)(Math.random() * getPossibleSpots(s, r)));
}
something like that could work
it's kind of terrible, but should be a uniform distribution