Yes, it keeps trying.
The key is that you only add to the variable i if the random value is not in the array.
That way, as long as i is less than the desired number of random numbers in the array, it keeps trying.
The variable Tries isn't really necessary to make it work. It is there just to show you how many times it had to loop to get the desired number of unique values. Say you are trying to generate 4 variables (the width of the array). If Tries=10 that means you had to loop 10 times to get 4 unique values.