int random(int N)
{
int x;
do{
x=rand()%(N*2+1)-N;
}while(x==0);
return x;
}
He selects a number from -N to N, but continues to do so if it is 0.
An alternative, as suggested in the comments, generates a number between -N and N-1 and increments it if it is positive or 0:
int random(int N)
{
int x;
x=rand()%(N*2)-N;
if(x>=0) x++;
return x;
}
source
share