title: How to Generate a -complete- sudoku board? algorithm error
body: <p>I'm trying to generate a complete (ie, each cell filled with a number) Sudoku-like board. It's for something else that has nothing to do with sudokus, so I am not interested in reaching a sudoku with white squares that can be solved, or anything that has to do with sudokus. Don't know if you know what I mean.</p>
  <p>I've done this in java:</p>
  <pre><code>private int sudokuNumberSelector(int x, int y, int[][] sudoku) {
  
      
      boolean valid = true;
      String validNumbers = new String();
      int[] aValidNumbers;
      int squarexstart = 0;
      int squareystart = 0;
      int b = 0;                          // For random numbers
      Random randnum = new Random();
      randnum.setSeed(new Date().getTime());
      
      // Check numbers one by one
      for(int n = 1; n &lt; 10; n++) {
          
          valid = true;
          
          // Check column
          for(int i = 0; i &lt; 9; i++) {
              if(sudoku[i][y] == n) {
                  valid = false;
              }
          }
          
          // Check file
          for(int j = 0; j &lt; 9; j++) {
              if(sudoku[x][j] == n) {
                  valid = false;
              }
          }
          
          // Check square
          switch (x) {
          case 0: case 1: case 2: squarexstart = 0; break;
          case 3: case 4: case 5: squarexstart = 3; break;
          case 6: case 7: case 8: squarexstart = 6; break;
          }
          
          switch (y) {
          case 0: case 1: case 2: squareystart = 0; break;
          case 3: case 4: case 5: squareystart = 3; break;
          case 6: case 7: case 8: squareystart = 6; break;
          }
          
          for(int i = squarexstart; i &lt; (squarexstart + 3); i++ ) {
              for(int j = squareystart; j &lt; (squareystart + 3); j++ ) {
                  if(sudoku[i][j] == n) {
                      valid = false;
                  }
              }
          }
          
          // If the number is valid, add it to the String
          if(valid) {
              validNumbers += n;
          }
      }
      
      if(validNumbers.length() != 0) {
                  
          // String to int[]
          aValidNumbers = fromPuzzleString(validNumbers);
          
          // By this random number, return the valid number in its position
          Log.d(TAG, &quot;NUMBERS: &quot; + validNumbers.length()); 
          
          // Select a random number from the int[]
          b = randnum.nextInt((aValidNumbers.length));
          
              
          return aValidNumbers[b];
  
      } else {
          return 0;
      }
  }
  </code></pre>
  <p>This method is called from this piece of code:</p>
  <pre><code>int[][] sudoku = new int[9][9];
  
  for(int i = 0; i &lt; 9; i++) {
              for(int j = 0; j &lt; 9; j++) {
                  sudoku[i][j] = sudokuNumberSelector(i, j, sudoku);
              }
          }
  </code></pre>
  <p>But it is not as easy as it seemed! When the algorithm has generated a part of the board like this one, and the loop is on the cell on bold:</p>
  <pre><code>|||164527389|||
  |||983416257|||
  |||257938416|||
  |||719352648|||
  |||3256791**0**0|||
  |||000000000|||
  |||000000000|||
  |||000000000|||
  |||000000000|||
  </code></pre>
  <p>There are no numbers to put in this cell, because all the numbers according to the rules of sudoku are already on the column, row or square!</p>
  <p>It is a nightmare for me. Is there any way to this to work? If not, i guess I have to redo everything as if I were making a Sudoku game.</p>