vendredi 30 janvier 2015

rand() giving same number each time [duplicate]


This question already has an answer here:




I'm using the rand() function to set up my game board, however every time I run my program it gives me the exact same values. I want the row/col positions to be random each time the program is run. Here's my code:



for (int x = 0; x < 30; x++)
{
int rowPos = (rand()%(21))+1;
int colPos = (rand()%(21))+1;
if(GetCellState(b, rowPos, colPos) != 7)
SetCellState(b, rowPos, colPos, 7);
else
--x;
}




Aucun commentaire:

Enregistrer un commentaire