I tried to create a matrix of random numbers ranging from 1 to 75 for a bingo game.But I am not able to generate distinct numbers please help.The first row should have no from 1 to 15,2nd row from 16 to 30,3rd row from 31 to 45,4th row from 46 to 60 and 5th row from 61 to 75.
void creatingbingo()
{ int ar[5][5],values[5],i,j,k,n;
//creating bingo ticket
//initializing the values of ticket
for(i=0;i<=4;i++)
{
values[i]=0;
}
for(i=0;i<=4;i++)
{
for(j=0;j<=4;j++)
{
loop:k=0;
do
{
uniform_int_distribution<int> rows (((15*(i+1)-15+1)),(15*(i+1)));
n=rows(randgenerate);
if(values[k]==n)
{
k=0;
goto loop;
}
else
{
values[k++]=n;
}
}while(k<5);
ar[i][j]=values[j];//filling the ticket
}
}
//displaying the ticket
for(i=0;i<5;i++)
{
for(j=0;j<5;j++)
{
cout<<ar[i][j]<<'\t';
}
cout<<endl;
}
}
An example of output which I got is:
11 14 8 5 10
16 26 24 25 19
41 45 38 43 31
55 52 60 53 60
62 70 71 68 75
Aucun commentaire:
Enregistrer un commentaire