I wrote a program that generates twenty random numbers. the chance of repeating the program is about 1/3. How can I rebuild my program? could anyone help me?
for (int i = 0; i <= 19; i++) {
rand[i] = (int) (Math.random() * 60 + 1);
}
for(int i=0;i<=19;i++)
{
rand_back[i]=rand[i];
}
for (int i = 0; i<=19;) {
for(int j=0;j<=19;j++) {
//porównaj czy wsytapiła juz taka sama liczba
if((rand[i]==rand_back[j])&&(j!=i)) {
rand[j]=(int) (Math.random()*60+1);
}
if(j==19){
j=0;
i++;
}
if(i==19) {
break;
}
}
if(i==19) {
break;
}
}
Aucun commentaire:
Enregistrer un commentaire