I was thinking about finding all possible combination for squares with number.

? ? ? ? ?

? ? 2 ? ?

? 2 2 1 1

? ? 1 0 0

? ? 1 0 0

In this example i will find all possible locations for every number. For example square 2 in second row.

? X ? ? ?

? X 2 ? ?

? 2 2 1 1

? ? 1 0 0

? ? 1 0 0

? ? X ? ?

? X 2 ? ?

? 2 2 1 1

? ? 1 0 0

? ? 1 0 0

? ? ? X ?

? X 2 ? ?

? 2 2 1 1

? ? 1 0 0

? ? 1 0 0

? ? ? ? ?

? X 2 X ?

? 2 2 1 1

? ? 1 0 0

? ? 1 0 0

? X X ? ?

? ? 2 ? ?

? 2 2 1 1

? ? 1 0 0

? ? 1 0 0

? X ? X ?

? ? 2 ? ?

? 2 2 1 1

? ? 1 0 0

? ? 1 0 0

? X ? ? ?

? ? 2 X ?

? 2 2 1 1

? ? 1 0 0

? ? 1 0 0

? ? X X ?

? ? 2 ? ?

? 2 2 1 1

? ? 1 0 0

? ? 1 0 0

? ? X ? ?

? ? 2 X ?

? 2 2 1 1

? ? 1 0 0

? ? 1 0 0

? ? ? X ?

? ? 2 X ?

? 2 2 1 1

? ? 1 0 0

? ? 1 0 0

There are 10 possible locations for mines around this square. If we find possible locations for all squares with number, then we can calculate probability without guessing and also we can be sure that all possible consistent combinations are found and here in your algorithm we do random distribution and we can't be sure for bigger tables that all consistent possibilities were computed.