How to solve an empty sudoku? I am making a computer game sudoku.
I have a simple algorithm(more like a rule) : check rows and columns before placing a number.
But solving like that sometimes get me stuck and I want to avoid correction algorithm unless there is no choice.
here is a case :
Fill any diagonal matrices with random numbers 0-9 :

Now pick one matrix and by the rule fill the numbers randomly :

But this step has a problem as shown in picture.
How to overcome that problem ? 
P.S : I need a solved sudoku in order to turn it into a question.
 A: Not a strong answer, but probably worth writing everything. Any sudoku with less than 17 numbers does not have a unique solution. So, randomly guessing 16 numbers will likely have at least one solution, and could be found by lots of trial and error. Computers could make this easier. 
Mind you, even with 16 numbers, no solution is guaranteed, but there are multiple "paths" to check.
A sudoku with 17 or more numbers MAY have a unique solution, or MAY not have a solution. It also MAY have multiple solutions. If you want to be sure you have multiple paths to take, don't work up to 17.
A: It seems like you are trying to construct any valid sudoku from scratch to then use for your game. If you are not willing to use a backtracking guess and check method, here's one algorithm (of many possible) that always produces a valid sudoku:
Given any 3x3 square with nine distinct elements, a 9x9 Sudoku can be constructed in exactly the way you started.
Let $L_{1}$ =
\begin{array}{|c|c|c|}
\hline
a & b & c \\ \hline
d & e & f \\ \hline
g & h & i \\ \hline
\end{array}  
then $L_{2}$ = 
\begin{array}{|c|c|c|}
\hline
i & g & h \\ \hline
c & a & b \\ \hline
f & d & e \\ \hline
\end{array}  
and $L_{3}$ = 
\begin{array}{|c|c|c|}
\hline
e & f & d \\ \hline
h & i & g \\ \hline
b & c & a \\ \hline
\end{array}  
Note that $L_{2}$ is a diagonal shift of $L_{1}$ where the rows are shifted down once (with the bottom row wrapping around to the top) and the columns are shifted right once (with the rightmost row wrapping around to the left). The same shift on $L_{2}$ is used to produce $L_{3}$.
For a given element $l$ in $L_{i}$, let $P_{i}(l) = \big( Row_{i}(l), Col_{i}(l) \big)$.
As a result of the construction of the subsquares, $i \not= j \implies Row_{i}(l) \not=Row_{j}(l) \wedge Col_{i}(l) \not=Col_{j}(l)$  
Now, make any 3x3 Latin Square out of the subsquares $L_{1}, L_{2},$ and $L_{3}$ and you're done.
The result will be very regular. You can permute the result without affecting its validity in a few ways.


*

*any set of three adjacent rows or columns (1-3), (4-6), (7-9) can be swapped with another set of three adjacent rows or columns.

*any pair of rows or pair of columns both inside of the above mentioned sets can be swapped.

*any pair of elements can be swapped across the whole sudoku (turning all a to b and all b to a)


J. Hammer and D. Hoffman, Factor pair latin squares, Australas. J. Combin., 69(1) (2017), 41-57
