im trying to write a function that gets an array, generate 8 Different Coordination I have some struct Array size 8 that save some Coordination in other array([8][8]). Im trying to Get eight Different coordination. But Unfortunately, I get some coordination. here is the code :
struct location {
int x;
int y;
};
void setCoordinations(struct locaction loc[]) /// the array is empty.
{
int i = 0, j = 8;
srand(time(NULL));
array[i]._row = rand() % 8;
array[i]._coulmn = rand() % 8;
for (int i = 1; i <8; i++)
{
array[i]._row = (rand() +i) % 8;
array[i]._coulmn = (rand() -j) % 8;
}
sometimes i get the same coordinations
Thank you for your help.
Aucun commentaire:
Enregistrer un commentaire