title: Sudoku generator algorithm
body: <p>I made an algorithm to generate sudokus, but it was terribly inefficient. Each puzzle took minutes to generate. So now I am trying to write it again in optimal way. But I am experiencing some problems I need help with.</p>
  <p>There are two aproaches:</p>
  <ol>
  <li>Start with blank grid and add numbers, then check if it is solvable.</li>
  <li>Create full valid grid with all 81 numbers and then remove until we are happy with number of remaining numbers and it is still solvable.</li>
  </ol>
  <p>First I used first approach but now I am going to use second because I think it is more effective (we are starting with valid puzzle which is guaranteed to be solvable). I am right that second approach is better?</p>
  <p>When I am trying to generate full populated grid I am running into difficulties. My algorithm is:</p>
  <ul>
  <li>Set candidates for each cells. Initialy they are numbers 1 through 9.</li>
  <li>Pick random cell without value.</li>
  <li>Select random candidate from that cell and assign it as cell value. Other candidates are discarded.</li>
  <li>Now for each row, cell and square corresponding to assigned cell I remove value of cell from these candidates, so each number is unique in a row/column/square</li>
  <li>Repeat</li>
  </ul>
  <p>This technique guarantees random grid without duplicate numbers. However, most of times, when I do not break any rules of placement a run to conflict - like empty cells where all candidates have been removed etc and I need to start over. Is there more elegant/efficient way to filling entire grid with numbers without breaking rules of placement and still random numbers?</p>