I'd rather just avoid as much (mathematical) overhead as possible, and stick with r^2 = x^2 + y^2 (I am assuming I can just use d(iameter) = x^2 + y^2 though, which is the distance...).
Yeh um that technically will be slower due to how slow JASS is. Most people go with the first method due to how much simpler and shorter the code is.
Anyway for such method you do the following (these are not real functions, but just to give you the idea)...
x = randomreal(0, distance) // random within right side of origin
y = (distance^2 - x^2)^0.5 // corresponding point above origin
if randomint(0, 1) == 1 then x = -x // randomly reflect x around origin so left side is covered
if randomint(0, 1) == 1 then y = -y // randomly reflect y around origin so bottom is covered
return offsetpoint(origin, x, y) // offset origin by x and y
As you can see it needs quite of lot of powers and at least 3 random calls.
The usual approach is.
a = randomreal(0, 2pi) // random angle
x = distance * Cos(a) // x offset
y = distance * Sin(a) // y offset
return offsetpoint(origin, x, y) // offset origin by x and y
Which needs no powers, only 1 random call but performs a Cos and Sin call. Since Cos and Sin solve virtually instantly compared with the JASS interpreter it is highly likely to be faster than the first approach. I only mentioned the first approach as an alternative to show that it can be solved without using Cos/Sin.
How do the two relate? It all comes down to how powers work, specifically complex powers. By mapping x as real and y as imaginary you can convert any point in this complex plain to a complex number such that the real part represents magnitude from the origin and the complex part represents angle by using the ln function. In fact this is how all powers work and how one can easily solve problems such as (-3)^1.5.
where j is the imaginary unit.
-3 = e^(ln(3) + jpi)
Substitute back.
e^(ln(3) + jpi)^1.5 = e^(1.5*ln(3) + j1.5*pi)
j1.5*pi means the output is negative imaginary (at 270 degrees in the complex plain)
1.5*ln(3) = ln(3^1.5) through the properties on log natural.
Solve magnitude
e^ln(3^1.5) = 3^1.5
This means (-3)^1.5 = -5.1961524227066318805823390245176
j