C#完成洗牌算法。本站提示廣大學習愛好者:(C#完成洗牌算法)文章只能為提供參考,不一定能成為您想要的結果。以下是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/>"); } }
以上就是本文給年夜家分享的洗牌算法的全體內容了,願望年夜家可以或許愛好。