0

I'm currently building a plane loading simulation, and am using the rand() function in C to generate a random number between 0 and some upper bound in order to allocate passengers to their seats.

Therefore, once a passenger has been allocated, I don't want the rand() function to select that passengers seat/row again. That is, I want that number to be taken out of the selection pool that rand() selects from.

Is there a way to do this? I know I can simply check if it has been selected and re-select if it has, but I was wondering if there was another way.

Thanks!

Btw, here is a snippet of the code for some context

int row = rand() % amount_rows/2; // don't want to select the same row/col twice
int col = rand() % amount_cols;
        
if (1 != passengers[row][col].in_row) {
    passengers[row][col].in_row = 1;
}

0 Answers0