I have 2 players, I want each of them to receive 26 random out of this 52 card deck. Does anyone have any idea how I can give each player, 26 random cards from the 52 card deck? This should empty the original 52 card Deck Dictionary, and create 2 smaller 26 card deck dictionary.

Here is my Deck Class:

`class Deck { public Dictionary<int, string> CreateNewDeck() { Dictionary<int, string> newDeck = new Dictionary<int, string>() { {1, "~/cards/c1.png"}, {2, "~/cards/c2.png"}, {3, "~/cards/c3.png"}, {4, "~/cards/c4.png"}, {5, "~/cards/c5.png"}, {6, "~/cards/c6.png"}, {7, "~/cards/c7.png"}, {8, "~/cards/c8.png"}, {9, "~/cards/c9.png"}, {10, "~/cards/c10.png"}, {11, "~/cards/cj.png"}, {12, "~/cards/cq.png"}, {13, "~/cards/ck.png"}, {14, "~/cards/d1.png"}, {15, "~/cards/d2.png"}, {16, "~/cards/d3.png"}, {17, "~/cards/d4.png"}, {18, "~/cards/d5.png"}, {19, "~/cards/d6.png"}, {20, "~/cards/d7.png"}, {21, "~/cards/d8.png"}, {22, "~/cards/d9.png"}, {23, "~/cards/d10.png"}, {24, "~/cards/dj.png"}, {25, "~/cards/dq.png"}, {26, "~/cards/dk.png"}, {27, "~/cards/h1.png"}, {28, "~/cards/h2.png"}, {29, "~/cards/h3.png"}, {30, "~/cards/h4.png"}, {31, "~/cards/h5.png"}, {32, "~/cards/h6.png"}, {33, "~/cards/h7.png"}, {34, "~/cards/h8.png"}, {35, "~/cards/h9.png"}, {36, "~/cards/h10.png"}, {37, "~/cards/hj.png"}, {38, "~/cards/hq.png"}, {39, "~/cards/hk.png"}, {40, "~/cards/s1.png"}, {41, "~/cards/s2.png"}, {42, "~/cards/s3.png"}, {43, "~/cards/s4.png"}, {44, "~/cards/s5.png"}, {45, "~/cards/s6.png"}, {46, "~/cards/s7.png"}, {47, "~/cards/s8.png"}, {48, "~/cards/s9.png"}, {49, "~/cards/s10.png"}, {50, "~/cards/sj.png"}, {51, "~/cards/sq.png"}, {52, "~/cards/sk.png"}, }; return newDeck; } } `

And here is the method I am trying to write to divide the deck:

class Dealer { public Dictionary<int, string> DealPlayersDeck(Deck deck, Player human, Player computer) { Deck cards = new Deck(); Player humanPlayer = new Player(); Player computerPlayer = new Player();

` var fullDeck = cards.CreateNewDeck(); var playerDeck = humanPlayer.PlayerCards; var computerDeck = computerPlayer.PlayerCards; int halfDeck = fullDeck.Count() / 2; foreach (object i in fullDeck) { List<int> keyList = new List<int>(fullDeck.Keys); Random rand = new Random(); int randomKey = keyList[rand.Next(keyList.Count)]; if (!playerDeck.ContainsKey(randomKey)) { playerDeck.Add(randomKey, fullDeck[randomKey]); fullDeck.Remove(randomKey); } //return fullDeck[randomKey]; } return playerDeck; } } `

by Suruat via /r/csharp