'How do I use Queues to randomize images?

I previously asked a question about randomizing images in Windows Form application (Visual Studio) for an Uno game. I was suggested an approach using queues. I'm afraid that I can't get it to work, mostly because I can't figure out how to queue the files and then dequeue them when the files are applied to the image boxes. How can I do this?



Solution 1:[1]

Forgot using queues for randomizing. What you need to do is:

  1. Create Card Objections with everything you need
  2. Create a List of the Cards
  3. Shuffle the list

Here is an example of how to do that

private static Random rng = new Random();
public static void Shuffle<T>(this IList<T> list)  
{  
    int n = list.Count;  
    while (n > 1) {  
        n--;  
        int k = rng.Next(n + 1);  
        T value = list[k];  
        list[k] = list[n];  
        list[n] = value;  
    }  
}
  1. Create a new queue from the list var queue = new Queue(list);
  2. Use the Enqueue and Dequeue commands to draw.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 MrMoonMan