Hey guys I'm quite new to Java, and just started meddling with classes. I'm currently trying to simulate a dice on a basic game I'm creating. The dice seems to work, but I can only call it effectively once, as the number always remains the same after that. Is there an easy solution for the dice I've created to be difference every time I call it?
public class Dice {
Random randomNum = new Random();
public int diceRoll() {
int diceResult = 0;
int result = randomNum.nextInt(20) + 1;
diceResult = diceResult + result;
return diceResult;
}
}
Appreciate any help in the slightest, thank you.
Aucun commentaire:
Enregistrer un commentaire