Translate 0 to infinity ratio to a 0-1 range

50 Views Asked by At

I'm a programmer and terrible with math notations, so sorry for the bad formatting.

I have tree points, lets call them P, A and B. I have the distance from P to A and P to B, and I want to choose the point A or B randomly, but weighted depending on what is closer.

So if P to A is 2 units, and P to B is 14 units, I want to have a much higher chance of getting A. The exact chances or not terribly important, but if A is like 10 times further, is should basically be 10 times more likely.

So for I have this:

PA = P to A  
PB = P to B
Ratio = PA / PB
NormRatio = sigmoid(Ratio)
if (NormRatio < Random(0, 1))  
   Choose A  
else  
   Choose B

Now, I'm aware what ranges a sigmoid function works over, so this does not work. But I suspect the answer something along these lines.

Can anybody point me in the right direction?

Thanks!