This is my below code in which I am trying to generate random unique number between 0 and 1001 and pass that number to some method. But this code gives me index out of bound exception. I am not sure why it is giving me that exception. Can anyone suggest me why is it happening?
If you wanted it to be unique couldn't you just generate a random number using the java.util.Random class nested in a do while loop (until a boolean turns true meaning the new number was added) Then every time you generate a new random number you run through the array using a for loop checking each index to see if it matches the randomly generated number. If not add it to the array and turn the boolean true.