vendredi 23 mars 2018

How to use srand and rand to continuously generate new numbers?

In my main funtion, the function fragment below is looped to keep generating two numbers between 0 and 4. The first time it goes through the loop it works fine, but the second time it gets core dumped. I'm not sure if it's because of a bug somewhere else or if I just didn't use the rand and srand properly. Very new to c language here.

void generate_player2_move(char board[][SIZE], int row, int col) {
    //segmentation fault (core dumped) somewhere around here.
    int randrow, randcol;
    srand((unsigned) randrow);
    srand((unsigned) randcol);  

    row = rand() % 4;
    col = rand() % 4;
}




Aucun commentaire:

Enregistrer un commentaire