I\'m trying to do the Fisher Yates shuffle on a list of Cards. I\'ve scoured forums and the only implementation of Fisher Yates is with normal int arrays like below
Surely the logic is exactly the same? The only different is that you are reading a Card from your collection rather than an int, i.e.
for (int i = Cards.Count - 1; i > 0; i--)
{
int j = random.Next(i + 1);
Card temp = Cards[i]; // Notice the change on this line
Cards[i] = Cards[j];
Cards[j] = temp;
}
After fixing up the programming errors mentioned in the comment, this implementation seems to work for me.