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:
void gen_puzzle(int quanti)
{
if(quanti>81) exit(1);
indexes* ij=new indexes[quanti];
int f,g,k, controllo=1;
do
{
for(f=0; f<9; f++)
for(g=0; g<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<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<quanti; f++)
for(g=f+1; g<quanti; g++)
{
if(ij[f].i==ij[g].i && (ij[f].j==ij[g].j)) goto out;
}
////////////////////
for(k=0; k<quanti; k++)
puzzle[ij[k].i][ij[k].j] . num=casuale();//puts random numbers in cells
}
while(dataNotGood()); //till sudoku isn't good
}
I ask help for section where the funcion puts random indexes in ij[] array, i used a "goto" but it's not a good solution and it doesn't work well if "quanti" is bigger then 17 about. "casuale()" just returns a random number between 1 and 9. Thanks for help me improving this section.