Checking if randomNumber has already been generated

Howdy guys,

I am trying to finish get through the Matching card game - but am hitting some stumbling blocks when it comes to the random number generating. Chris alluded to this in the video, by using a while loop to get completely unique sets of numbers.

I cannot for the life of me, figure out how this is down.

Any help is appreciated.
As you can see I started to make another empty array, as well as a while loop but I keep getting to a spot where I don’t know how to proceed.

To have only unique values show here’s the steps I’d follow:

  1. Get a random number
  2. Use a for loop to check if that number has been used already
    3a. If it hasn’t, use that number
    3b. If it has, generate a new number. (Keep repeating until you find a unique number)

4a. Add this number to your used numbers array

I would do pretty much what @mikaelacaron suggested, but use a Set<Int> instead of an Array. For this particular purpose it almost certainly won’t matter much, but with larger amounts of data using a Set will gain you better performance because testing whether a Set contains an item is faster than testing an Array. Also, you won’t need a loop to do the test.