This is an assignment for school that I am really close to completing, but I don't have it exactly. I am supposed to generate an array of integer Nodes with 100 random numbers without duplicates by checking for duplicates. I'm not allowed to use a Set. I'm not allowed to just shuffle an array of numbers 1-1000.
Here is the code I have in my client class so far but it still creates duplicates:
for (int i = 0; i < SIZE; i++) {
int j = (int)(Math.random()*1999);
//put a random number in the first index.
if (i == 0) {
Node newNode = new Node(j);
nodeArray[i] = newNode;
}
for (int k = 0; k < i; k++) {
if (nodeArray[k].getInt() == j) {
j = (int)(Math.random()*1999);
break;
} else {
Node newNode = new Node(j);
nodeArray[i] = newNode;
}
}
}