title: generate a random point within rectangles' areas uniformly (some rectangles could overlap)
body: <p>Assume it's given a set of rectangles with different areas and some rectangles could overlap.
  Objective is generating of a uniform random point among rectangles' areas.</p>
  
  <p>Rectangle is defined as a pair of two points:</p>
  
  <ul>
  <li>(x1,y1) - bottom leftmost corner; </li>
  <li>(x2,y2) - top rightmost corner.</li>
  </ul>
  
  <p>My strategy for uniform distribution of a random point among not overlapped rectangles is that,- randomly select a rectangle based on areas (<a href="https://stackoverflow.com/questions/872563/efficient-algorithm-to-randomly-select-items-with-frequency">existing solution</a>):</p>
  
  <pre><code>   for(int i = 0; i &lt; rectangles.length; i++) {
        int area = (rectangles[i].x2 - rectangles[i].x1) * 
                   (rectangles[i].y1 - rectangles[i].y2);
           if(rand.nextInt(total + area) &gt;= total) {
               selected = i;
               break;
           }
           total += area;
     }
  </code></pre>
  
  <p>Then generate an arbitrary point within a rectangle:</p>
  
  <ul>
  <li>x1 +(1/(x2-x1))*rand(0,(x2-x1-1)), </li>
  <li>y1 +(1/(y2-y1))*rand(0,(y2-y1-1)).</li>
  </ul>
  
  <p>But how to be if some of rectangles could overlap?</p>