当前位置: 移动技术网 > IT编程>开发语言>c# > C#实现随机洗牌的方法

C#实现随机洗牌的方法

2019年07月18日  | 移动技术网IT编程  | 我要评论
本文实例讲述了c#实现随机洗牌的方法。分享给大家供大家参考。具体实现方法如下: 复制代码 代码如下:#region 随机洗牌  int[] ints = {

本文实例讲述了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#程序设计有所帮助。

如您对本文有疑问或者有任何想说的,请点击进行留言回复,万千网友为您解惑!

相关文章:

验证码:
移动技术网