So I am trying to make an Array with random numbers, but whenever I try Math.random
or create a new Random
object and use it, I always get the same number multiple times. My code is this one:
int[] Array = new int[size];
for (int Y : Array) {
Array[Y] = (int) (Math.random() * 10) + 3;
}
or this one:
int[] Array = new int[size];
for (int Y: Array) {
Array[Y] = rand.nextInt(30);
}
The output im getting is: [0][3][3][3][3][3][3][3][3][3][3][3][3][3][3][3][3][3][3][3][3][3][3][3][3][3][3][3][3][3]
I haven't set a seed and I tried it outside the loop and inside but still only get the same number.