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
Edit: Thank you for the feedback guys. It turned out my code was calling the original random value I used on an integer, as I didn't change its value to a new number everytime I was calling it.
Thanks again for helping me realize it wasn't the Dice class itself. Appreciate it! :)