The code will run ONLY as many times as the value of MaxElements. Since if chose 325 as MaxElements, it will only run 325 times, bypassing all the duplicate random values within the range of 1 to 325. Bypassing all the duplicates was what this challenge was all about.
Yes, if MAxElements were a large number, the code would run that many times, but not hindered by the duplicate checking logic. I think you assumed that the code would continue to run until it found all the unique values, which could take a long time.
In my original code, I threw in the Unique stuff just for drill, although it is not really part of the original challenge.