Generation

generate functionSat, 12 Nov 2022

Generate and shuffle a list of cards with 3 copies of each value 1 through 8.

public static List<int> GenerateAndShuffleDeck() { List<int> deck = new List<int>(); for (int i = 0; i < 8; i++) { deck.Add(i + 1); deck.Add(i + 1); deck.Add(i + 1); } Random random = new Random(); List<int> result = new List<int>(); while (deck.Count > 0) { int index = random.Next(deck.Count); result.Add(deck[index]); deck.RemoveAt(index); } return result; }

Questions about programming?Chat with your personal AI assistant