C# · 12月 28, 2021

C#实现洗牌算法

C#洗牌算法,简单演示!

/// <summary>/// 洗牌算法/// </summary>private void test(){ int[] iCards = new int[54]; for (int i = 0; i < iCards.Length; i++) { iCards[i] = i + 1; } // Random rand = new Random(); int iTarget = 0,iCardTemp = 0; for (int i = 0; i < iCards.Length; i++) { iTarget = rand.Next(0,iCards.Length); iCardTemp = iCards[i]; iCards[i] = iCards[iTarget]; iCards[iTarget] = iCardTemp; } for (int i = 0; i < iCards.Length; i++) { Response.Write(“第” + (i + 1) + “张牌是:” + iCards[i] + “<br/>”); }}

以上就是本文给大家分享的洗牌算法的全部内容了,希望大家能够喜欢。