mercredi 5 juillet 2017

Java: how to make an efficient chance method

Hi there im making a rewards code and im trying to make a good chance code i have this method for now,

 public int getRandom(int lower, int upper) {
        Random random = new Random();
        return random.nextInt((upper - lower) + 1) + lower;
    }


int chance = getRandom(0, 100);
if(chance < 10){
reward(player)
}

Is there a better method can make this code more efficient? sometimes it get random chance within 0 and 10 which gives the best reward.




Aucun commentaire:

Enregistrer un commentaire