The value of int bound in nextInt(int bound) method of Random should be equal to the number of times i loop executes else your intenal x loop will execute infinite time.
How?Suppose your outer loop i executes 5 times means It is
and you have value of int bound less than 5, assume 4 i.e. .nextInt(4); means this method can generate values 0, 1, 2, 3 so total 4 unique numbers
But you want to generate 5 unique values (No duplicates) whose code you wrote in inner x loop so It is not possible as already mentioned nextInt(4) generates only 0, 1, 2, 3 so inner x loop will execute infinite times just to get next 5th unique number which is not possible.
Regarding your next question, I think other members of this forum may answer you better than me and yes, you are welcome