一副扑克有52张牌,那么使用数组存储这52张牌,然后打乱这些牌。
using System; using System.Collections.Generic; using System.Collections; using System.Linq; using System.Text; using System.Threading.Tasks; namespace Poker { class Program { static void Main(string[] args) { ArrayList al = new ArrayList(); for (int i = 1; i < 53; i++) { al.Add(i); } al = PokerSeqRandom(al); foreach (var item in al) { Console.Write(item+","); } } static ArrayList PokerSeqRandom(ArrayList al) { Random rd = new Random(); ArrayList result = new ArrayList(); while(al.Count>0) { int index = rd.Next(0, al.Count); result.Add((int)al[index]); al.RemoveAt(index); } return result; } } }