码迷,mamicode.com
首页 > Windows程序 > 详细

C#实现随机洗牌的方法

时间:2017-12-14 04:20:47      阅读:252      评论:0      收藏:0      [点我收藏+]

标签:end   ted   reg   write   http   otto   des   orm   ack   

本文实例讲述了C#实现随机洗牌的方法。分享给大家供大家参考。具体实现方法如下:


代码如下:

#region 随机洗牌

int[] ints = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20 };

List<int> list=ints.ToList();

int[] outs = new int[20];

Random rand = new Random();

for (int i = 0; i < 20; i++)

{

int x = rand.Next(list.Count);

outs[i] = list[x];

list.RemoveAt(x);

}

Response.Write(“<hr/>”);

foreach (int i in outs)

{

Response.Write(i.ToString() + ” “);

}

#endregion

希望本文所述对大家的C#程序设计有所帮助。

除声明外,跑步客文章均为原创,转载请以链接形式标明本文地址
  C#实现随机洗牌的方法

本文地址:  http://www.paobuke.com/develop/c-develop/pbk23140.html






相关内容

C#实现随机洗牌的方法

标签:end   ted   reg   write   http   otto   des   orm   ack   

原文地址:http://www.cnblogs.com/paobuke/p/8035494.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!