How to get a random element from an array thats different from previous one?

You could just use a while loop and generate a random int. You are already doing that but with more unnecesary steps.