I want to populate a grid with 1s and 0s. My program crashes due to the random variable r. It works perfectly fine with a constant(eg: say r=8). I have used srand(time(NULL));
void initGrid(int grid[GRID_HEIGHT][GRID_WIDTH])
{
int i,j,r;
for(i=0;i<GRID_HEIGHT;i++)
{
r = rand()%10;
for(j=0;j<GRID_WIDTH;j++)
{
grid[i][j]= (i*j+i+j)%(r)<=2?1:0;
}
}
}
Aucun commentaire:
Enregistrer un commentaire