title: How to randomly choose screen positions for drawing same bitmap
body: <p>I am trying to draw a 20x20 size bitmap at random positions on the screen. I want that the bitmaps should not overlap each other and should be scattered uniformly.</p>
  
  <p>For accomplishing this, I am generating the positions as below -</p>
  
  <pre><code>void function() {
     int bitmap_size = 20*20;
     int i, width = 320, height = 480;
     int numslots = width*height/bitmap_size;
  
     int *array = malloc(sizeof(int)*numslots);
     for(i=0; i&lt;numslots; i++)
        array[i] = i;
  
     // Randomize pixel indices
     for(i=0; i&lt;numslots; i++) {
        int x = (rand()%(numslots-i)) + i;
        swap(array+i, array+x);
     }
  
     // Generate positions for 20 bitmaps
     for(i=0; i&lt;20; i++) {
        int pos = array[i];
        pos *= bitmap_size;
        int y = pos / height;
        int x = pos % width;
        printf("%d, %d\n", x, y);
     }
  
     free(array);
  }
  </code></pre>
  
  <p>However, when i run this code, the pixel positions are somewhat cluttered as you can see from the sample output (x, y) below for 20 positions -</p>
  
  <pre><code>240, 85
  160, 255
  80, 37
  240, 115
  80, 280
  160, 118
  0, 223
  80, 170
  80, 147
  240, 45
  0, 253
  160, 225
  160, 261
  0, 66
  80, 230
  80, 30
  0, 236
  80, 27
  160, 238
  0, 200
  </code></pre>
  
  <p>3 positions are at x=240, 5 positions are at x=160 and x=0 each and 7 positions are at x=80. How to generate more uniformly scattered locations for the bitmaps?</p>