I call this function 10 times in my program, but the random numbers never change between calls. Why not and how can I fix this?
CODE
void placeShips(char gameBoard[][COLUMNS], char ship, int strength)
{
int i, c, row, col, horizPlace;
//seed random number generator
srand(time(NULL));
//decide wether ship will be horizontaly or verticly aligned
horizPlace = (rand() % 2);
//randomly pick a starting point for a ship
row = (rand() % 10); //HERE
col = (rand() % 10); //AND HERE
if (gameBoard[row][col] == '~')
{
gameBoard[row][col] = ship;
if (horizPlace == YES)
{
for(c = 1; c < strength; c++)
gameBoard[row][col + c] = ship;
}
else
{
for(c = 1; c < strength; c++)
gameBoard[row + c][col] = ship;
}
}
printf("\n \n %d %d", row, col);
}
This post has been edited by camaroer87: 13 Apr, 2008 - 03:25 PM