I can very well imagine that your code goes into an eternal loop, it's rather buggy. For example, the first random number created for each position in the array will always be replaced by a new random number, as you regard it as a duplicate as it is equal to itself. Also, if a number is the same as the first in the array, you pick a new number and accept it without checking if the new number is the same as the first in the array. Perhaps not the most efficient, but very simple and straight forward: Put all the possible numbers in a list. Pick one of them by random and remove it from the list. Repeat until you have the desired number of numbers.
--- b { font-weight: normal; }