im having trouble generating 2500 random number with an specific range (0 to 4) and a specific quantity ( 1000 times 1, 3 times 2, 2 times 3 and 4 and the rest of the numbers are to be 0) i got this peace of code right here but it is not working either it loops or just doesn't generate the specific quantity of numbers im requiring
thanks in advance for the help.
public int [][] map (){
for (int i =0; i<50; i++){
for (int j =0; j<50; j++){
do{
chek=false;
Random rand = new Random();
n=rand.nextInt(5);
switch (n) {
case 1:
plant++; // keeps track of how many times a number has been generated
break;
case 2:
ant++;
break;
case 3:
papabear++;
break;
case 4:
mamabear++;
break;
}
if (plant>=1000){ // quantity of numbers needed
chek=false;
}
else if (ant>=3){
chek=false;
}
else if (papabear>=2){
chek=false;
}
else if (mamabear>=2){
chek=false;
}
}while (chek==true); // if chek==false it loops
distribution [i][j]=n;
}
}
return distribution;
}
Aucun commentaire:
Enregistrer un commentaire