Usually, when I want a chance of something happening I use a random number, then an if statement to check for a specific outcome, like so:
public static void main(String[] args){
public boolean chance(){
Random r = new Random();
int chance = Random(100)+1; //For a 1/100 chance
if(chance == 1){
return true;
}else{
return false;
}
}
}
Are there more efficient ways to do this in java, like a java library method, or am I stuck with creating it every time I want to use a percent chance.
Aucun commentaire:
Enregistrer un commentaire