I want to generate a 100 unique random numbers, but the numbers need to be in the range of 1-10. Right now I am doing this:
for (int i = 0; i < 100; i++) {
Double n = rand.nextDouble(10) + 1;
arr[i] = n;
}
I could get Double numbers by checking if they're unique using if/else statements in arrays but it is very difficult and inefficient because the numbers(Doubles) could be almost infinite.
So how do i make sure the numbers are unique without using arrays?
Are there any data structures in java which do not allow duplicate elements?