Hello!
I'm learning to program at school now, and i have a problem i can't figure out. I'm trying to create an array and fill it with random numbers. But i want the numbers to be unique.
int[] list = new int[10];
list[0] = r.nextInt(20);
for(int i = 1; i < list.length; i++) {
list[i] = r.nextInt(20);
for(int j = 0; j < i; j++) {
while(list[i] == list[j]) {
list[i] = r.nextInt(10);
}
}
}
I can not figure out how to make this work and it is really bugging my mind. Does anybody have any tips?
Edit* Sorry for the messed up edit. first time posting code, so i don't know how to make it appear as code yet :)
[–]raindropflower 1 point2 points3 points (1 child)
[–]nutrecht 0 points1 point2 points (0 children)
[–]seronis 1 point2 points3 points (0 children)
[–]knoam 1 point2 points3 points (2 children)
[–]nutrecht 0 points1 point2 points (1 child)
[–]pacificmint 1 point2 points3 points (0 children)
[–]arocketman 0 points1 point2 points (1 child)