Mathematics Stack Exchange is a question and answer site for people studying math at any level and professionals in related fields. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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.

share|cite|improve this question
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…. 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:… (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:… – Frenzy Li Dec 19 '12 at 1:58
up vote 3 down vote accepted

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

share|cite|improve this answer
This worked perfectly for me, thank you. – AkBKukU Dec 19 '12 at 0:10

Another way. Choose a random angle between 0 and 2PI. Then choose a random number between 0 and r. pt(x,y) =

Note that it isn't uniform.

share|cite|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.