This is a good answer here. though stil has a room to improve.
What is happening here?
whatever the random() function generate, placed it on an 'arr' array type variable. each num generated will be evaluated from the isRecurred() custom function if its already been generated. If its not then display it. else, the variable i reverses from its previous position to regenerate random number.