title: Randomly generate points in an Image in a selected ROI. (Image J macro)
body: <p>I am trying to put n dots randomly on a selected ROI in an image using the macro;</p>
  <pre><code>Roi.getBounds(x,y,w,h);
  count = 0;
  while (count &lt; n) { 
      roiManager( &quot;select&quot;, 0 ); // select the first, &quot;big&quot; ROI
      x1 = random() * w + x;
      y1 = random() * h + y;
      if (selectionContains(x1, y1) == true ) { // if coordinates are inside the &quot;big&quot; ROI 
          makePoint(x1, y1); // generate random point
          roiManager(&quot;Add&quot;);// add the point to the ROI Manager
          count++; // ONLY increase count when point is added
      }
  }
  
  </code></pre>
  <p>But now, I want a condition that I should not get (x,y) in a (x-1,y-1), (x+1,y+1) neighbourhood. How can I write ths in the code? (no 2 points should be closer by 1 pixel).</p>