C#实现洗牌算法
发布时间:2016-12-28 来源:查字典编辑
摘要:C#洗牌算法,简单演示!//////洗牌算法///privatevoidtest(){int[]iCards=newint[54];for(...
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/>"); } }
以上就是本文给大家分享的洗牌算法的全部内容了,希望大家能够喜欢。