# Constrain Random Numbers to Inside a Circle

I am generating two random numbers to choose a point in a circle randomly. The circles radius is 3000 with origin at the center. I'm using -3000 to 3000 as my bounds for the random numbers. I'm trying to get the coordinates to fall inside the circle (ie 3000, 3000 is not in the circle). What equation could I use to test the limits of the two numbers because I can generate a new one if it falls out of bounds.

-
Why don't you have your random number generator generate numbers that are mapped to be inside the circle as to avoid this? For example, a strategy simlar to stackoverflow.com/questions/137783/…. Also, you can look in Knuth's or in Numerical Recipes, CH 7 for such algorithms to figure out how to map them to a specified range. – Amzoti Dec 18 '12 at 22:43
@Amzoti Actually, the first recommendation in Knuth for generating random points in a circle, IIRC, is the 'generate a new one' rejection sampling approach that the OP mentions - it sounds like they're just trying to figure out how to implement it. – Steven Stadnicki Dec 18 '12 at 22:48
Well then, they can find that here: stackoverflow.com/questions/5837572/… (look at the last method for quick and dirty or one of the earilier methods with the nice pictures) Regards -A – Amzoti Dec 18 '12 at 22:54
Possible 2D Duplicate of: math.stackexchange.com/questions/91109/… – Frenzy Li Dec 19 '12 at 1:58

Compare $x^2+y^2$ with $r^2$ and reject / retry if $x^2+y^2\ge r^2$.