Note that there are some explanatory texts on larger screens.

plurals
  1. PORandom sudoku generation
    primarykey
    data
    text
    <p>I'm writing a function that should generate random sudoku puzzles for a simulation project; this funcion takes as argoument the number of cells to generate then it generates the indexes of cells and numbers to put in those cells. I have a problem in generation of cells indexes, I'm not an expert in programming and i can't find a good routine to generate indexes and to check out not to be the same index couple two times or more. The funcion is:</p> <pre><code>void gen_puzzle(int quanti) { if(quanti&gt;81) exit(1); indexes* ij=new indexes[quanti]; int f,g,k, controllo=1; do { for(f=0; f&lt;9; f++) for(g=0; g&lt;9; g++) { puzzle[f][g].num=0;//puts 0 in the sudoku puzzle puzzle[f][g].p=0; } //////////////section to improve out: srand(int(time(0)+clock())); for(k=0; k&lt;quanti; k++) ij[k].i=casuale()-1, ij[k].j=casuale()-1;//generates random indexes of sudoku cells where put random nubers for(f=0; f&lt;quanti; f++) for(g=f+1; g&lt;quanti; g++) { if(ij[f].i==ij[g].i &amp;&amp; (ij[f].j==ij[g].j)) goto out; } //////////////////// for(k=0; k&lt;quanti; k++) puzzle[ij[k].i][ij[k].j] . num=casuale();//puts random numbers in cells } while(dataNotGood()); //till sudoku isn't good } </code></pre> <p>I ask help for section where the funcion puts random indexes in <code>ij[]</code> array, i used a <code>goto</code> but it's not a good solution and it doesn't work well if <code>quanti</code> is bigger then 17 about.<br> <code>casuale()</code> just returns a random number between 1 and 9.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload