I am creating a game where a user has to roll two dice and do certain things according to what is rolled. I have one method for rolling the dice, which I call twice to stimulate rolling two dice.
import java.util.Random;
public class test {
public static int dice() {
Random generator = new Random(System.currentTimeMillis());
return generator.nextInt(6) +1;
}
public static void main(String[] args) {
int roll1 = dice();
int roll2 = dice();
System.out.println(roll1);
System.out.println(roll2);
}
}
Consistently, the same number is returned for both rolls, even though they are being called separately.
Note: I was seeding the Random generator with the current time to avoid this.
Any help is much appreciated, I am new to Java!