Generate random coordinates from area outside of a rectangle?

Posted by Rockmaninoff on Stack Overflow See other posts from Stack Overflow or by Rockmaninoff
Published on 2010-04-29T20:21:38Z Indexed on 2010/04/29 20:27 UTC
Read the original article Hit count: 460

Hi all,

I'm working on a simple tutorial, and I'd like to randomly generate the positions of the red and green boxes in the accompanying images anywhere inside the dark gray area, but not in the white area. Are there any particularly elegant algorithms to do this? There are some hackish ideas I have that are really simple (continue to generate while the coordinates are not outside the inside rectangle, etc.), but I was wondering if anyone had come up with some neat solutions.

Thanks for any help!

alt text

© Stack Overflow or respective owner

Related posts about random

Related posts about random-number-generator