Need help understanding the shuffle cards method

I don’t understand the //shuffle cards thing.

 //assigning values to each card in the grid
  int[] values = new int[20];
  for (int i=0; i<icons.length; i++) {
   icons[i] = loadImage(filename[i]);
    values[2*i] = i;
    values[2*i+1] = i;

  //shuffle cards
  for (int i=0; i<values.length; i++) {
    int r = int(random(values.length));
    int t = values[i];
    values[i] = values[r];
    values[r] = t;

1 Like

This part does a swapping of two items in your array. Your i counter is going through every element in your number container in order, from the first to the last. The r counter is a random item in your list, calculated every time you step in your array.



thank you :slight_smile: