<p>Adding another answer for generating a sudoku of desired difficulty on-the-fly.</p>

<p>This means that unlike other approaches the algorithm runs <strong>only once</strong> and returns a sudoku configuration matching the desired difficulty (<strong>with high probability within a range or with probability=1</strong>)</p>

<p>Various solutions for generating (and rating) a sudoku difficulty have to do with <a href="http://www.learn-sudoku.com/basic-techniques.html" rel="nofollow noreferrer"><em>human-based</em> techniques and approaches</a>, which can be <em>easily</em> rated.</p>

<p>Then one (after having generated a sudoku configuration) <strong>re-solves</strong> the sudoku with the human-like solver and depending on the techniques the solver used (e.g <em>pairs</em>, <em>x-wing</em>, <em>swordfish</em> etc.) a difficulty rate is also assigned.</p>

<p><strong>Problems with this approach</strong> 
(and requirements for the use case i had)</p>

<ol>
<li><p>In order to generate a sudoku with given difficulty, with previous method one needs to solve a sudoku twice (once with the basic algorithm and once with the human-like solver).</p></li>
<li><p>One has to (pre-)generate many sudokus which can only be rated as to difficulty <strong>after being solved</strong> by the human-like solver. So one cannot generate a desired sudoku on-the-fly once.</p></li>
<li><p>The human-like solver can be complicated and in most cases (if not all) is tightly coupled to 9x9 sudoku grids. So no easy generalisation to other sudokus (e.g 4x4, 16x16, 6x6 etc.)</p></li>
<li><p>The difficulty rating of the human-like techniques is very subjective. For example why <em>x-wing</em> is taken to be more difficult than <em>hidden singles</em>? (personaly have solved many difficult published sudoku puzzles manualy and never used such techniques)</p></li>
</ol>

<p>Another approach was used which has the following benefits:</p>

<ol>
<li>Generalises well to arbitrary sudokus (9x9, 4x4, 6x6, 16x16 etc..)</li>
<li>The sudoku configuration, with desired difficulty, is generated once and on-the-fly</li>
<li>The difficulty rating is objective.</li>
</ol>

<p><strong>How it works?</strong></p>

<p>First of all, the simple fact that <strong>the more difficult the puzzle, the more time it needs to be solved</strong>.</p>

<p>But time to be solved is intimately correlated to both number of clues (givens) and average alternatives to be investigated per empty cell.</p>

<p>Extending my <a href="https://stackoverflow.com/a/25110517/3591273">previous answer</a>, it was mentioned that for any sudoku puzzle the minimum number of clues is an objective property of the puzzle (for example <a href="http://arxiv.org/abs/1201.0749" rel="nofollow noreferrer"><strong>for 9x9 grids the minimum number of clues for having a valid sudoku is 17</strong></a>)</p>

<p>One can start from there and compute minimum number of clues per difficulty level (linear correlation).</p>

<p>Furthermore at each step of the sudoku generation process, one can make sure the average alternatives (to be investigated) per empty cell is within given bounds (as a function of desired difficulty)</p>

<p>Depending on whether the algorithm uses backtrack or not (for the use case discussed the algorithm does no backtracking) the desired difficulty can be reached either with probability=1 or with high probability within bounds (respectively).</p>

<p>Tests of the sudokus generated with this algorithm and difficulty rating based on the previous approaches (human-like solver), show a correlation of desired and estimated difficulty rates, plus a greater ability for generalisation to arbitrary sudoku configurations.</p>

<p>(have used this online <a href="http://www.sudoku-solutions.com/" rel="nofollow noreferrer">sudoku solver</a> (and also <a href="http://www.stolaf.edu/people/hansonr/sudoku/analyst.htm" rel="nofollow noreferrer">this one</a>) to correlate the difficulty rates of the test sudokus)</p>

<p>The code is available free <a href="https://github.com/foo123/sudoku.js" rel="nofollow noreferrer">on github sudoku.js (along with sample demo application)</a>, a scaled-down version of CrossWord.js a professional crossword builder in JavaScript, by same author</p>
Generating a sudoku of a desired difficulty?
<p>So, I've done a fair bit of reading into generation of a Sudoku puzzle. From what I can tell, the standard way to have a Sudoku puzzle of a desired difficulty is to generate a puzzle, and then grade it afterwards, and repeat until you have one of an acceptable rating. This can be refined by generating via backtracing using some of the more complex solving patterns (XY-wing, swordfish, etc.), but that's not quite what I'm wanting to do here.</p>

<p>What I want to do, but have been unable to find any real resource on, is generate a puzzle from a "difficulty value" (0-1.0 value, 0 being the easiest, and 1.0 being the hardest). </p>

<p>For example, I want create a moderately difficult puzzle, so the value .675 is selected. Now using that value I want to be able to generate a moderately difficult puzzle.</p>

<p>Anyone know of something like this? Or perhaps something with a similar methodology?</p>