title: How to select distinct random points in grid
body: <p>I have a 2D list, I need to select <code>n</code> distinct random points (x, y coordinates) from this 2D list. Let me first write what occured to me when I tried to solve the problem.</p>
  
  <p>Let's say the grid is <code>300 x 400</code>.</p>
  
  <ul>
  <li>Do cartesian product <code>300 x 400</code> get a list of <code>120000</code> elements, than use <code>random.choice</code> <strong>(Slow for large grids)</strong></li>
  <li>Keep the selected points in a set, randomize again in a while loop if a duplicate point is produced. <strong>(Very slow and unpredictable if n is large)</strong></li>
  </ul>
  
  <p>I searched some similar questions in SO, none of them address the problem directly. I did found <a href="https://stackoverflow.com/questions/10754392/different-random-points-from-a-2-dimensional-grid">This question</a>, though the users answer the problem, they do not offer a Python solution, which we may produce here in this question. Maybe usage of appropriate data structures in Python standard library can be suggested if not code itself.</p>