Did you make sure to add this code?

Qt Code:
  1. bool set = false;
  2. while(!set)
  3. {
  4. aux2=int( rand()%20);
  5. aux3=int( rand()%20);
  6. if(math[aux2][aux3]==0)
  7. {
  8. math[aux2][aux3] = 1;
  9. set = true;
  10. }
  11. }
To copy to clipboard, switch view to plain text mode 

The while loop should keep running until you have set a value to 0. This added in conjunction with the initialization to 0 should fix your problem. Also, if you have the bool in the wrong place then the loop will
not work.