Is a there a neat algorithm that I can use to fill in random positions in a huge 2D *n* x *n* array with *m* number of integers without filling in an occupied position? Where ![nformula](https://chart.googleapis.com/chart?cht=tx&chl=n%20%5Cgeq%20100), and ![mformula](https://chart.googleapis.com/chart?cht=tx&chl=m%20%5Cleq%20%5Cfrac%7Bn%5E%7B2%7D%7D%7B90%7D)

Kind of like this pseudo code:

```
int n;
int m;

void init(int new_n, int new_m) {
    n = new_n;
    m = new_m;
}
void create_grid() {
    int grid[n][n];

    int x, y;
    for(x = 1; x <= n; x ++) {
        for(y = 1; y <= n; y ++) {
            grid[x][y] = 0;
        }
    }

    populate_grid(grid);
}

void populate_grid(int grid[][]) {
    int i = 1;
    int x, y;

    while(i <= m) {
        x = get_pos();
        y = get_pos();

        if(grid[x][y] == 0) {
            grid[x][y] = i;
            i ++;
        }
    }
}

int get_pos() {
    return random() % n + 1;
}

```

... but more efficient for bigger n's and m's. Specially if m is bigger and more positions are being occupied, it would take longer to generate a random position that isn't occupied.