- ·上一篇内容:在C#中进行位操作
- ·下一篇内容:使用C#自己制作字幕屏幕保护程序
快速生成指定大小的随机不重复int数组的方法
一个用来快速生成指定大小的随机不重复int数组的实用方法
/// <summary>
/// 随机产生考场号
/// </summary>
/// <param name="start">初始值</param>
/// <param name="count">数量</param>
/// <returns></returns>
public static List<int> GetRandomList(int start, int count)
{
List<int> list = new List<int>();
List<int> temp = new List<int>();
for (int i = start; i < count + start; i++)
{
temp.Add(i);
}
Random ro = new Random();
while (list.Count < count)
{
int a = ro.Next(0, temp.Count);
if (!list.Contains(temp[a]))
{
list.Add(temp[a]);
temp.Remove(temp[a]);
}
}
return list;
}
原问地址:http://www.cnblogs.com/13142088/archive/2011/01/31/1948175.html
本文源自:翔宇亭——IT乐园(http://www.biye5u.com),转载请保留此信息!
微信搜索“优雅的代码”关注本站的公众号,或直接使用微信扫描下面二维码关注本站公众号,以获取最新内容。
个人成长离不开各位的关注,你的关注就是我继续前行的动力。