I'm a novice Java programmer and need to create two random numbers. We were instructed to use System.currentTimeMillis() however I don't know why I am getting so many repeated numbers.
import java.util.Random;
public class TestClass1 {
public static void main(String[] args) {
int points = 0;
while (points < 100) {
int[] scoreInfo = diceGen();
System.out.println(scoreInfo[0]);
System.out.println(scoreInfo[1]);
points += 1;
}
}
public static int[] diceGen() {
Random num = new Random(System.currentTimeMillis());
int dice1 = num.nextInt(6)+1;
int dice2 = num.nextInt(6)+1;
int[] numbers = {dice1, dice2};
return numbers;
}
}
Output: 6 6 6 6 6 6 6 6 6 6 6 6 6 6 4 2 4 2 4 2 4 2 4 2 4 2 4 2 4 2 4 2 4 2 4 2 4 2 4 2 4 2 4 2 3 4 3 4 3 4 3 4 3 4 3 4 3 4 3 4 3 4 3 4 3 4 3 4 3 4 3 4 1 4 1 4 1 4 1 4 1 4 1 4 1 4 1 4 1 4 1 4 1 4 1 4 1 4 1 4 1 4 1 4 1 4 1 4 2 6 2 6 2 6 2 6 2 6 2 6 2 6 2 6 2 6 2 6 2 6 2 6 2 6 2 6 2 6 2 6 6 2 6 2 6 2 6 2 6 2 6 2 6 2 6 2 6 2 6 2 6 2 6 2 6 2 6 2 6 2 6 2 6 2 6 2 6 5 6 5 6 5 6 5 6 5 6 5 6 5 6 5 6 5 6 5 6 5 6 5